diff --git a/core/modules/content_translation/config/schema/content_translation.field_settings.schema.yml b/core/modules/content_translation/config/schema/content_translation.field_settings.schema.yml deleted file mode 100644 index dfdb104..0000000 --- a/core/modules/content_translation/config/schema/content_translation.field_settings.schema.yml +++ /dev/null @@ -1,21 +0,0 @@ -# Schema for field settings for the Content Translation module. - -content_translation.field_settings: - type: mapping - label: 'Content translation field settings' - mapping: - translation_sync: - type: sequence - label: 'Field translation synchronisation settings' - sequence: - - type: sequence - label: 'Entity type' - sequence: - - type: sequence - label: 'Bundle' - sequence: - - type: sequence - label: 'Field' - sequence: - - type: string - label: 'Column' diff --git a/core/modules/content_translation/config/schema/content_translation.settings.schema.yml b/core/modules/content_translation/config/schema/content_translation.settings.schema.yml new file mode 100644 index 0000000..f61248f --- /dev/null +++ b/core/modules/content_translation/config/schema/content_translation.settings.schema.yml @@ -0,0 +1,32 @@ +# Schema for the settings for the Content Translation module. + +#content_translation.settings: +# type: sequence +# label: 'Entity type' +# sequence: +# - type: sequence +# label: 'Bundle' +# sequence: +# - type: mapping +# label: 'Content translation settings' +# mapping: +# content_translation: +# type: mapping +# mapping: +# enabled: +# type: boolean +# label: 'Content translation status' +# fields: +# type: sequence +# sequence: +# - type: boolean +# label: 'Per field content translation' +# translation_sync: +# type: sequence +# label: 'Field translation synchronisation settings' +# sequence: +# - type: sequence +# label: 'Field' +# sequence: +# - type: string +# label: 'Column' diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index b416173..b8b3f94 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -38,7 +38,7 @@ function content_translation_field_sync_widget(FieldInstanceConfigInterface $fie // Create an associative array of column groups, keyed on column name, with // the value of disabled columns set to FALSE. - $translation_sync = content_translation_get_field_config($field, 'translation_sync') ?: array(); + $translation_sync = content_translation_get_field_sync($field) ?: array(); $default = array_map(function ($value) use ($translation_sync) { return in_array($value, $translation_sync) ? $value : FALSE; }, array_combine(array_keys($default), array_keys($default))); diff --git a/core/modules/content_translation/content_translation.install b/core/modules/content_translation/content_translation.install index b814f2d..ec888b4 100644 --- a/core/modules/content_translation/content_translation.install +++ b/core/modules/content_translation/content_translation.install @@ -88,19 +88,6 @@ function content_translation_install() { // hook_module_implements_alter() is run among the last ones. module_set_weight('content_translation', 10); \Drupal::service('language_negotiator')->saveConfiguration(Language::TYPE_CONTENT, array(LanguageNegotiationUrl::METHOD_ID => 0)); - - $config_names = \Drupal::configFactory()->listAll('field.field.'); - foreach ($config_names as $name) { - \Drupal::config($name) - ->set('settings.translation_sync', FALSE) - ->save(); - } - $config_names = \Drupal::configFactory()->listAll('field.instance.'); - foreach ($config_names as $name) { - \Drupal::config($name) - ->set('settings.translation_sync', FALSE) - ->save(); - } } /** diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index c6286c1..56e0a73 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -316,14 +316,13 @@ function content_translation_set_config($entity_type, $bundle, $setting, $value) * * @param \Drupal\field\FieldInstanceConfigInterface $field * The field for which to retrieve the value. - * @param string $setting - * The field setting to retrieve. * * @return mixed|NULL * The configuration value, or NULL if no value was set. */ -function content_translation_get_field_config(FieldInstanceConfigInterface $field, $setting) { - return \Drupal::config('content_translation.field_settings')->get($setting . '.' . $field->id()); +function content_translation_get_field_sync(FieldInstanceConfigInterface $field) { + $key = _content_translation_get_field_sync_key($field); + return \Drupal::config('content_translation.settings')->get($key); } /** @@ -331,13 +330,12 @@ function content_translation_get_field_config(FieldInstanceConfigInterface $fiel * * @param \Drupal\field\FieldInstanceConfigInterface $field * The field for which to store the value. - * @param string $setting - * The field setting to store. * @param mixed $value * The configuration to store. */ -function content_translation_set_field_config(FieldInstanceConfigInterface $field, $setting, $value) { - \Drupal::config('content_translation.field_settings')->set($setting . '.' . $field->id(), $value)->save(); +function content_translation_set_field_sync(FieldInstanceConfigInterface $field, $value) { + $key = _content_translation_get_field_sync_key($field); + \Drupal::config('content_translation.settings')->set($key, $value)->save(); } /** @@ -345,11 +343,26 @@ function content_translation_set_field_config(FieldInstanceConfigInterface $fiel * * @param \Drupal\field\FieldInstanceConfigInterface $field * The field for which to clear the configuration. - * @param string $setting - * The field setting to clear. */ -function content_translation_clear_field_config(FieldInstanceConfigInterface $field, $setting) { - \Drupal::config('content_translation.field_settings')->clear($setting . '.' . $field->id())->save(); +function content_translation_clear_field_sync(FieldInstanceConfigInterface $field) { + $key = _content_translation_get_field_sync_key($field); + \Drupal::config('content_translation.settings')->clear($key)->save(); +} + +/** + * Creates translation sync configuration key. + * + * @param FieldInstanceConfigInterface $field + * The field for which to create the key. + * + * @return string + * The configuration key. + */ +function _content_translation_get_field_sync_key(FieldInstanceConfigInterface $field) { + $entity_type = preg_replace('/[^0-9a-zA-Z_]/', "_", $field->getTargetEntityTypeId()); + $bundle = preg_replace('/[^0-9a-zA-Z_]/', "_", $field->targetBundle()); + $field_name = preg_replace('/[^0-9a-zA-Z_]/', "_", $field->getField()->getName()); + return $entity_type . '.' . $bundle . '.translation_sync.' . $field_name; } /** @@ -739,7 +752,7 @@ function content_translation_form_field_ui_field_instance_edit_form_alter(array */ function content_translation_form_field_ui_field_instance_edit_form_submit($form, array &$form_state) { $value = array_keys(array_filter($form_state['values']['instance']['settings']['translation_sync'])); - content_translation_set_field_config($form_state['instance'], 'translation_sync', $value); + content_translation_set_field_sync($form_state['instance'], $value); } /** @@ -909,12 +922,12 @@ function content_translation_save_settings($settings) { $column_settings = array_keys(array_filter($column_settings)); $instance = field_info_instance($entity_type, $field_name, $bundle); if ($instance->isTranslatable()) { - content_translation_set_field_config($instance, 'translation_sync', $column_settings); + content_translation_set_field_sync($instance, $column_settings); } // If the field does not have translatable enabled we need to reset // the sync settings to their defaults. else { - content_translation_clear_field_config($instance, 'translation_sync'); + content_translation_clear_field_sync($instance); } $instance->save(); } diff --git a/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php b/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php index 4d42d9e..09e7e2e 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php @@ -61,8 +61,8 @@ public function synchronizeFields(ContentEntityInterface $entity, $sync_langcode // Sync if the field is translatable, not empty, and the synchronization // setting is enabled. - $key = 'translation_sync.' . $entity->getEntityTypeId() . '.' . $entity->bundle() . '.' . $field_name; - if ($field_definition->isTranslatable() && !$items->isEmpty() && $translation_sync = \Drupal::config('content_translation.field_settings')->get($key)) { + $key = $entity->getEntityTypeId() . '.' . $entity->bundle() . '.translation_sync.' . $field_name; + if ($field_definition->isTranslatable() && !$items->isEmpty() && $translation_sync = \Drupal::config('content_translation.settings')->get($key)) { // Retrieve all the untranslatable column groups and merge them into // single list. $groups = array_diff(array_keys($field_type_definition['column_groups']), $translation_sync); diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php index eb93da9..5f6a265 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\entity\Tests\ContentTranslationSyncImageTest. + * Contains \Drupal\content_translation\Tests\ContentTranslationSyncImageTest. */ namespace Drupal\content_translation\Tests; @@ -64,12 +64,13 @@ protected function setupTestFields() { 'translatable' => TRUE, ))->save(); - entity_create('field_instance_config', array( + $field_instance = entity_create('field_instance_config', array( 'entity_type' => $this->entityTypeId, 'field_name' => $this->fieldName, 'bundle' => $this->entityTypeId, 'label' => 'Test translatable image field', - ))->save(); + )); + $field_instance->save(); // Enable content translation for image field on the test entity. $settings = array( @@ -86,8 +87,8 @@ protected function setupTestFields() { // Enable content translation for the 'alt' and 'title' properties on the // image field. $settings = array('alt', 'title'); - $key = 'translation_sync.' . $this->entityTypeId . '.' . $this->entityTypeId . '.' . $this->fieldName; - \Drupal::config('content_translation.field_settings')->set($key, $settings)->save(); + $key = _content_translation_get_field_sync_key($field_instance); + \Drupal::config('content_translation.settings')->set($key, $settings)->save(); } /**