commit ca9f6afc2ff254bbf6059e05cb9ce12f04b99ea0 Author: Pieter Frenssen Date: Fri Mar 28 15:21:08 2014 +0100 2224761-22 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 index 2f1dfd6..dfdb104 100644 --- 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 @@ -1,8 +1,21 @@ # Schema for field settings for the Content Translation module. -content_translation.field_settings.translation_sync.*.*.*: - type: sequence - label: 'Fields that have translation synchronisation enabled' - sequence: - - type: string - label: 'Field group column' +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/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 313feb8..14077fc 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -6,7 +6,6 @@ */ use Drupal\Component\Utility\String; -use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; use Drupal\field\Field as FieldService; use Drupal\field\FieldInstanceConfigInterface; @@ -14,13 +13,13 @@ /** * Returns a form element to configure field synchronization. * - * @param \Drupal\Core\Field\FieldDefinitionInterface $field - * A field definition object. + * @param \Drupal\field\FieldInstanceConfigInterface $field + * A field instance. * * @return array * A form element to configure field synchronization. */ -function content_translation_field_sync_widget(FieldDefinitionInterface $field) { +function content_translation_field_sync_widget(FieldInstanceConfigInterface $field) { $element = array(); $definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getType()); @@ -38,7 +37,7 @@ function content_translation_field_sync_widget(FieldDefinitionInterface $field) // Create an associative array of column groups, keyed on column name, with // the value of disabled columns set to FALSE. - $translation_sync = \Drupal::config('content_translation.field_settings')->get('translation_sync.' . $field->id()) ?: array(); + $translation_sync = content_translation_get_field_config($field, 'translation_sync') ?: 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.module b/core/modules/content_translation/content_translation.module index 98761a3..9432e49 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -14,6 +14,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\TranslatableInterface; +use Drupal\field\FieldInstanceConfigInterface; use Drupal\node\NodeInterface; /** @@ -384,6 +385,47 @@ function content_translation_set_config($entity_type, $bundle, $setting, $value) } /** + * Retrieves the value for the given field setting. + * + * @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()); +} + +/** + * Stores configuration for the given field setting. + * + * @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(); +} + +/** + * Clears the configuration for the given field setting. + * + * @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(); +} + +/** * Determines whether the given entity type is translatable. * * @param string $entity_type @@ -765,9 +807,8 @@ function content_translation_form_field_ui_field_instance_edit_form_alter(array * Form submission handler for 'field_ui_field_instance_edit_form'. */ function content_translation_form_field_ui_field_instance_edit_form_submit($form, array &$form_state) { - $key = 'translation_sync.' . $form_state['instance']->id(); $value = array_keys(array_filter($form_state['values']['instance']['settings']['translation_sync'])); - \Drupal::config('content_translation.field_settings')->set($key, $value)->save(); + content_translation_set_field_config($form_state['instance'], 'translation_sync', $value); } /** @@ -937,13 +978,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()) { - \Drupal::config('content_translation.field_settings')->set('translation_sync.' . $entity_type . '.' . $bundle . '.' . $field_name, $column_settings)->save(); + content_translation_set_field_config($instance, 'translation_sync', $column_settings); } // If the field does not have translatable enabled we need to reset // the sync settings to their defaults. else { - $key = 'translation_sync.' . $entity_type . '.' . $bundle . '.' . $field_name; - \Drupal::config('content_translation.field_settings')->clear($key)->save(); + content_translation_clear_field_config($instance, 'translation_sync'); } $instance->save(); }