diff --git a/core/config/schema/core.data_types.schema.yml b/core/config/schema/core.data_types.schema.yml index 33369bd..4356141 100644 --- a/core/config/schema/core.data_types.schema.yml +++ b/core/config/schema/core.data_types.schema.yml @@ -374,6 +374,11 @@ field_config_base: label: 'Default value function' settings: type: field.[%parent.field_type].instance_settings + third_party_settings: + type: sequence + label: 'Third party settings' + sequence: + - type: field_config.third_party.[%key] field_type: type: string label: 'Field type' diff --git a/core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php b/core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php index 536a4cb..0836eaf 100644 --- a/core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php +++ b/core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php @@ -80,11 +80,6 @@ protected function checkValue($key, $value) { $error_key = $this->configName . ':' . $key; $element = $this->schema->get($key); if ($element instanceof Undefined) { - // @todo Temporary workaround for https://www.drupal.org/node/2224761. - $key_parts = explode('.', $key); - if (array_pop($key_parts) == 'translation_sync' && strpos($this->configName, 'field.') === 0) { - return array(); - } return array($error_key => 'Missing schema.'); } diff --git a/core/lib/Drupal/Core/Field/FieldConfigInterface.php b/core/lib/Drupal/Core/Field/FieldConfigInterface.php index 1207356..68bdb70 100644 --- a/core/lib/Drupal/Core/Field/FieldConfigInterface.php +++ b/core/lib/Drupal/Core/Field/FieldConfigInterface.php @@ -72,4 +72,18 @@ public function targetBundle(); */ public function setDefaultValue($value); + /** + * Sets the value of a third-party setting for the plugin. + * + * @param string $module + * The module providing the third-party setting. + * @param string $key + * The setting name. + * @param mixed $value + * The setting value. + * + * @return $this + */ + public function setThirdPartySetting($module, $key, $value); + } diff --git a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php index 2236d59..5cf45fa 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php +++ b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php @@ -193,4 +193,21 @@ public function getFieldStorageDefinition(); */ public function getConfig($bundle); + /** + * Returns the value of a third-party setting, or $default if not set. + * + * @param string $module + * The module providing the third-party setting. + * @param string $key + * The setting name. + * @param mixed $default + * (optional) The default value if the third party setting is not set. + * Defaults to NULL. + * + * @return mixed|NULL + * The setting value. Returns NULL if the setting does not exist and + * $default is not provided. + */ + public function getThirdPartySetting($module, $key, $default = NULL); + } diff --git a/core/modules/content_translation/config/schema/content_translation.schema.yml b/core/modules/content_translation/config/schema/content_translation.schema.yml new file mode 100644 index 0000000..3037e8a --- /dev/null +++ b/core/modules/content_translation/config/schema/content_translation.schema.yml @@ -0,0 +1,9 @@ +# Schema for the Content Translation module. + +field_config.third_party.content_translation: + type: mapping + label: 'Content translation field settings' + mapping: + translation_sync: + type: sequence + label: 'Field properties for which to synchronize translations' diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 768b891..d808768 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -38,12 +38,11 @@ function content_translation_field_sync_widget(FieldDefinitionInterface $field) $settings = array('dependent_selectors' => array('instance[settings][translation_sync]' => array('file'))); - $translation_sync = $field->getSetting('translation_sync'); $element = array( '#type' => 'checkboxes', '#title' => t('Translatable elements'), '#options' => $options, - '#default_value' => !empty($translation_sync) ? $translation_sync : $default, + '#default_value' => $field->getThirdPartySetting('content_translation', 'translation_sync', $default), '#attached' => array( 'library' => array( 'content_translation/drupal.content_translation.admin', diff --git a/core/modules/content_translation/content_translation.install b/core/modules/content_translation/content_translation.install index 06a355b..4aa7e73 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(LanguageInterface::TYPE_CONTENT, array(LanguageNegotiationUrl::METHOD_ID => 0)); - - $config_names = \Drupal::configFactory()->listAll(\Drupal::entityManager()->getDefinition('field_storage_config')->getConfigPrefix() . '.'); - 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(); - } } /** @@ -118,21 +105,3 @@ function content_translation_enable() { $message = t('Enable translation for content types, taxonomy vocabularies, accounts, or any other element you wish to translate.', $t_args); drupal_set_message($message, 'warning'); } - -/** - * Implements hook_uninstall(). - */ -function content_translation_uninstall() { - $config_names = \Drupal::configFactory()->listAll(\Drupal::entityManager()->getDefinition('field_storage_config')->getConfigPrefix() . '.'); - foreach ($config_names as $name) { - \Drupal::config($name) - ->clear('settings.translation_sync') - ->save(); - } - $config_names = \Drupal::configFactory()->listAll('field.instance.'); - foreach ($config_names as $name) { - \Drupal::config($name) - ->clear('settings.translation_sync') - ->save(); - } -} diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index d8b2819..de2d11d 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -652,16 +652,6 @@ function content_translation_form_field_ui_field_instance_edit_form_alter(array * Implements hook_entity_presave(). */ function content_translation_entity_presave(EntityInterface $entity) { - // By default no column has to be synchronized. - // @todo Replace with own storage in https://drupal.org/node/2224761 - if ($entity->getEntityTypeId() === 'field_storage_config') { - $entity->settings += array('translation_sync' => FALSE); - } - // Synchronization can be enabled per instance. - // @todo Replace with own storage in https://drupal.org/node/2224761 - if ($entity->getEntityTypeId() === 'field_instance_config') { - $entity->settings += array('translation_sync' => FALSE); - } if ($entity instanceof ContentEntityInterface && $entity->isTranslatable()) { // @todo Avoid using request attributes once translation metadata become // regular fields. diff --git a/core/modules/content_translation/src/FieldTranslationSynchronizer.php b/core/modules/content_translation/src/FieldTranslationSynchronizer.php index 196512b..3e03940 100644 --- a/core/modules/content_translation/src/FieldTranslationSynchronizer.php +++ b/core/modules/content_translation/src/FieldTranslationSynchronizer.php @@ -54,6 +54,7 @@ public function synchronizeFields(ContentEntityInterface $entity, $sync_langcode return; } + /** @var \Drupal\Core\Field\FieldItemListInterface $items */ foreach ($entity as $field_name => $items) { $field_definition = $items->getFieldDefinition(); $field_type_definition = $field_type_manager->getDefinition($field_definition->getType()); @@ -61,7 +62,7 @@ public function synchronizeFields(ContentEntityInterface $entity, $sync_langcode // Sync if the field is translatable, not empty, and the synchronization // setting is enabled. - if ($field_definition->isTranslatable() && !$items->isEmpty() && $translation_sync = $field_definition->getSetting('translation_sync')) { + if ($field_definition->isTranslatable() && !$items->isEmpty() && $translation_sync = $field_definition->getThirdPartySetting('content_translation', 'translation_sync')) { // Retrieve all the untranslatable column groups and merge them into // single list. $groups = array_keys(array_diff($translation_sync, array_filter($translation_sync))); diff --git a/core/modules/content_translation/src/FieldTranslationSynchronizerInterface.php b/core/modules/content_translation/src/FieldTranslationSynchronizerInterface.php index 0c60b18..0a5f38a 100644 --- a/core/modules/content_translation/src/FieldTranslationSynchronizerInterface.php +++ b/core/modules/content_translation/src/FieldTranslationSynchronizerInterface.php @@ -20,7 +20,8 @@ * Field column synchronization takes care of propagating any change in the * field items order and in the column values themselves to all the available * translations. This functionality is provided by defining a - * 'translation_sync' key in the field instance settings, holding an array of + * 'translation_sync' key for the 'content_translation' module's portion of + * the field definition's 'third_party_settings', holding an array of * column names to be synchronized. The synchronized column values are shared * across translations, while the rest varies per-language. This is useful for * instance to translate the "alt" and "title" textual elements of an image diff --git a/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php b/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php index 98b9540..6a8c499 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php @@ -62,11 +62,13 @@ protected function setupTestFields() { 'field_name' => $this->fieldName, 'bundle' => $this->entityTypeId, 'label' => 'Test translatable image field', - 'settings' => array( - 'translation_sync' => array( - 'file' => FALSE, - 'alt' => 'alt', - 'title' => 'title', + 'third_party_settings' => array( + 'content_translation' => array( + 'translation_sync' => array( + 'file' => FALSE, + 'alt' => 'alt', + 'title' => 'title', + ), ), ), ))->save();