diff --git a/core/modules/language/config/schema/language.schema.yml b/core/modules/language/config/schema/language.schema.yml index 2633fdc..3efe5d0 100644 --- a/core/modules/language/config/schema/language.schema.yml +++ b/core/modules/language/config/schema/language.schema.yml @@ -101,6 +101,27 @@ language.entity.*: type: boolean label: 'Locked' +language.content_settings.*: + type: config_entity + label: 'Content Language Settings' + mapping: + id: + type: string + label: 'ID' + entities: + type: sequence + label: 'Entity type' + sequence: + - type: mapping + label: 'Bundle' + mapping: + langcode: + type: string + label: 'Default language' + language_show: + type: boolean + label: 'Show language selector on create and edit pages' + language.settings: type: mapping label: 'Language settings' diff --git a/core/modules/language/language.module b/core/modules/language/language.module index a605360..b9c2197 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -5,6 +5,7 @@ * Add language handling functionality to Drupal. */ +use Drupal\Component\Utility\String; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Routing\RouteMatchInterface; @@ -213,7 +214,7 @@ function language_save_default_configuration($entity_type, $bundle, $values = ar * - language_show: if the language element is hidden or not. */ function language_get_default_configuration($entity_type, $bundle) { - $configuration = \Drupal::config('language.settings')->get(language_get_default_configuration_settings_key($entity_type, $bundle)); + $configuration = \Drupal::config('language.content_settings.' . String::checkPlain($entity_type))->get('entities.'. $bundle); if (is_null($configuration)) { $configuration = array(); } @@ -234,27 +235,6 @@ function language_clear_default_configuration($entity_type, $bundle) { } /** - * Returns the root name of the variables used to store the configuration. - * - * Based on the entity type and bundle, the variables used to store the - * configuration will have a common root name. - * - * @param string $entity_type - * A string representing the entity type. - * @param string $bundle - * A string representing the bundle. - * - * @return string - * The root name of the variables. - */ -function language_get_default_configuration_settings_key($entity_type, $bundle) { - // Replace all the characters that are not letters, numbers or "_" with "_". - $entity_type = preg_replace('/[^0-9a-zA-Z_]/', "_", $entity_type); - $bundle = preg_replace('/[^0-9a-zA-Z_]/', "_", $bundle); - return 'entities.' . $entity_type . '.' . $bundle . '.language.default_configuration'; -} - -/** * Implements hook_ENTITY_TYPE_update() for node_type entities. */ function language_node_type_update(NodeTypeInterface $type) { diff --git a/core/modules/language/src/Entity/ContentLanguageSettings.php b/core/modules/language/src/Entity/ContentLanguageSettings.php new file mode 100644 index 0000000..a745a5b --- /dev/null +++ b/core/modules/language/src/Entity/ContentLanguageSettings.php @@ -0,0 +1,46 @@ +entities = $entities; + + return $this; + } + +} diff --git a/core/modules/language/src/Form/ContentLanguageSettingsForm.php b/core/modules/language/src/Form/ContentLanguageSettingsForm.php index a415379..f3f743e 100644 --- a/core/modules/language/src/Form/ContentLanguageSettingsForm.php +++ b/core/modules/language/src/Form/ContentLanguageSettingsForm.php @@ -7,11 +7,13 @@ namespace Drupal\language\Form; +use Drupal\Component\Utility\String; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; +use Drupal\language\Entity\ContentLanguageSettings; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -145,16 +147,18 @@ public function buildForm(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $config = $this->config('language.settings'); foreach ($form_state->getValue('settings') as $entity_type => $entity_settings) { + $entities = []; foreach ($entity_settings as $bundle => $bundle_settings) { - $config->set(language_get_default_configuration_settings_key($entity_type, $bundle), array( + $entities[$bundle] = array( 'langcode' => $bundle_settings['settings']['language']['langcode'], 'language_show' => $bundle_settings['settings']['language']['language_show'], - )); + ); } + $config = new ContentLanguageSettings(['id' => $entity_type], 'content_language_settings'); + $config->setEntities($entities); + $config->save(); } - $config->save(); drupal_set_message($this->t('Settings successfully updated.')); }