Update to Drupal 8.0.5. For more information, see https://www.drupal.org/node/2679347
This commit is contained in:
parent
2a9f1f148d
commit
fd3b12cf27
251 changed files with 5439 additions and 957 deletions
|
@ -19,11 +19,14 @@ use Drupal\Core\Render\Element;
|
|||
*
|
||||
* @param \Drupal\Core\Field\FieldDefinitionInterface $field
|
||||
* A field definition object.
|
||||
* @param string $element_name
|
||||
* (optional) The element name, which is added to drupalSettings so that
|
||||
* javascript can manipulate the form element.
|
||||
*
|
||||
* @return array
|
||||
* A form element to configure field synchronization.
|
||||
*/
|
||||
function content_translation_field_sync_widget(FieldDefinitionInterface $field) {
|
||||
function content_translation_field_sync_widget(FieldDefinitionInterface $field, $element_name = 'third_party_settings[content_translation][translation_sync]') {
|
||||
// No way to store field sync information on this field.
|
||||
if (!($field instanceof ThirdPartySettingsInterface)) {
|
||||
return array();
|
||||
|
@ -33,15 +36,18 @@ function content_translation_field_sync_widget(FieldDefinitionInterface $field)
|
|||
$definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getType());
|
||||
$column_groups = $definition['column_groups'];
|
||||
if (!empty($column_groups) && count($column_groups) > 1) {
|
||||
$options = array();
|
||||
$default = array();
|
||||
$options = [];
|
||||
$default = [];
|
||||
$require_all_groups_for_translation = [];
|
||||
|
||||
foreach ($column_groups as $group => $info) {
|
||||
$options[$group] = $info['label'];
|
||||
$default[$group] = !empty($info['translatable']) ? $group : FALSE;
|
||||
if (!empty($info['require_all_groups_for_translation'])) {
|
||||
$require_all_groups_for_translation[] = $group;
|
||||
}
|
||||
}
|
||||
|
||||
$settings = array('dependent_selectors' => array('instance[third_party_settings][content_translation][translation_sync]' => array('file')));
|
||||
$default = $field->getThirdPartySetting('content_translation', 'translation_sync', $default);
|
||||
|
||||
$element = array(
|
||||
|
@ -49,15 +55,19 @@ function content_translation_field_sync_widget(FieldDefinitionInterface $field)
|
|||
'#title' => t('Translatable elements'),
|
||||
'#options' => $options,
|
||||
'#default_value' => $default,
|
||||
'#attached' => array(
|
||||
'library' => array(
|
||||
'content_translation/drupal.content_translation.admin',
|
||||
),
|
||||
'drupalSettings' => [
|
||||
'contentTranslationDependentOptions' => $settings,
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if ($require_all_groups_for_translation) {
|
||||
// The actual checkboxes are sometimes rendered separately and the parent
|
||||
// element is ignored. Attach to the first option to ensure that this
|
||||
// does not get lost.
|
||||
$element[key($options)]['#attached']['drupalSettings']['contentTranslationDependentOptions'] = [
|
||||
'dependent_selectors' => [
|
||||
$element_name => $require_all_groups_for_translation
|
||||
],
|
||||
];
|
||||
$element[key($options)]['#attached']['library'][] = 'content_translation/drupal.content_translation.admin';
|
||||
}
|
||||
}
|
||||
|
||||
return $element;
|
||||
|
@ -82,7 +92,6 @@ function _content_translation_form_language_content_settings_form_alter(array &$
|
|||
|
||||
$form['#attached']['library'][] = 'content_translation/drupal.content_translation.admin';
|
||||
|
||||
$dependent_options_settings = array();
|
||||
$entity_manager = Drupal::entityManager();
|
||||
foreach ($form['#labels'] as $entity_type_id => $label) {
|
||||
$entity_type = $entity_manager->getDefinition($entity_type_id);
|
||||
|
@ -110,13 +119,9 @@ function _content_translation_form_language_content_settings_form_alter(array &$
|
|||
'#default_value' => $definition->isTranslatable(),
|
||||
);
|
||||
// Display the column translatability configuration widget.
|
||||
$column_element = content_translation_field_sync_widget($definition);
|
||||
$column_element = content_translation_field_sync_widget($definition, "settings[{$entity_type_id}][{$bundle}][columns][{$field_name}]");
|
||||
if ($column_element) {
|
||||
$form['settings'][$entity_type_id][$bundle]['columns'][$field_name] = $column_element;
|
||||
// @todo This should not concern only files.
|
||||
if (isset($column_element['#options']['file'])) {
|
||||
$dependent_options_settings["settings[{$entity_type_id}][{$bundle}][columns][{$field_name}]"] = array('file');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,8 +137,6 @@ function _content_translation_form_language_content_settings_form_alter(array &$
|
|||
}
|
||||
}
|
||||
|
||||
$settings = array('dependent_selectors' => $dependent_options_settings);
|
||||
$form['#attached']['drupalSettings']['contentTranslationDependentOptions'] = $settings;
|
||||
$form['#validate'][] = 'content_translation_form_language_content_settings_validate';
|
||||
$form['#submit'][] = 'content_translation_form_language_content_settings_submit';
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
// We're given a generic name to look for so we find all inputs containing
|
||||
// that name and copy over the input values that require all columns to be
|
||||
// translatable.
|
||||
if (options.dependent_selectors) {
|
||||
if (options && options.dependent_selectors) {
|
||||
for (var field in options.dependent_selectors) {
|
||||
if (options.dependent_selectors.hasOwnProperty(field)) {
|
||||
$fields = $context.find('input[name^="' + field + '"]');
|
||||
|
|
|
@ -45,3 +45,19 @@ function content_translation_update_8001() {
|
|||
/**
|
||||
* @} End of "addtogroup updates-8.0.0-rc".
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup updates-8.0.x
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Clear field type plugin caches to fix image field translatability.
|
||||
*/
|
||||
function content_translation_update_8002() {
|
||||
\Drupal::service('plugin.manager.field.field_type')->clearCachedDefinitions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup updates-8.0.x".
|
||||
*/
|
||||
|
|
|
@ -14,6 +14,7 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\field\FieldConfigInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
|
@ -199,9 +200,17 @@ function content_translation_entity_base_field_info(EntityTypeInterface $entity_
|
|||
* which columns should be synchronized across different translations and
|
||||
* which are translatable. This is useful for instance to translate the
|
||||
* "alt" and "title" textual elements of an image field, while keeping the
|
||||
* same image on every translation.
|
||||
* same image on every translation. Each group has the following keys:
|
||||
* - title: Title of the column group.
|
||||
* - translatable: (optional) If the column group should be translatable by
|
||||
* default, defaults to FALSE.
|
||||
* - columns: (optional) A list of columns of this group. Defaults to the
|
||||
* name of he group as the single column.
|
||||
* - require_all_groups_for_translation: (optional) Set to TRUE to enforce
|
||||
* that making this column group translatable requires all others to be
|
||||
* translatable too.
|
||||
*
|
||||
* @see Drupal\image\Plugin\Field\FieldType\imageItem.
|
||||
* @see Drupal\image\Plugin\Field\FieldType\ImageItem
|
||||
*/
|
||||
function content_translation_field_info_alter(&$info) {
|
||||
foreach ($info as $key => $settings) {
|
||||
|
|
|
@ -66,6 +66,17 @@ class FieldTranslationSynchronizer implements FieldTranslationSynchronizerInterf
|
|||
// Retrieve all the untranslatable column groups and merge them into
|
||||
// single list.
|
||||
$groups = array_keys(array_diff($translation_sync, array_filter($translation_sync)));
|
||||
|
||||
// If a group was selected has the require_all_groups_for_translation
|
||||
// flag set, there are no untranslatable columns. This is done because
|
||||
// the UI adds Javascript that disables the other checkboxes, so their
|
||||
// values are not saved.
|
||||
foreach (array_filter($translation_sync) as $group) {
|
||||
if (!empty($column_groups[$group]['require_all_groups_for_translation'])) {
|
||||
$groups = [];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!empty($groups)) {
|
||||
$columns = array();
|
||||
foreach ($groups as $group) {
|
||||
|
@ -163,7 +174,16 @@ class FieldTranslationSynchronizer implements FieldTranslationSynchronizerInterf
|
|||
continue;
|
||||
}
|
||||
// If a synchronized column has changed or has been created from
|
||||
// scratch we need to override the full items array for all languages.
|
||||
// scratch we need to replace the values for this language as a
|
||||
// combination of the values that need to be synced from the source
|
||||
// items and the other columns from the existing values. This only
|
||||
// works if the delta exists in the language.
|
||||
elseif ($created && !empty($original_field_values[$langcode][$delta])) {
|
||||
$item_columns_to_sync = array_intersect_key($source_items[$delta], array_flip($columns));
|
||||
$item_columns_to_keep = array_diff_key($original_field_values[$langcode][$delta], array_flip($columns));
|
||||
$values[$langcode][$delta] = $item_columns_to_sync + $item_columns_to_keep;
|
||||
}
|
||||
// If the delta doesn't exist, copy from the source language.
|
||||
elseif ($created) {
|
||||
$values[$langcode][$delta] = $source_items[$delta];
|
||||
}
|
||||
|
|
|
@ -201,7 +201,9 @@ class ContentTranslationSyncUnitTest extends KernelTestBase {
|
|||
for ($delta = 0; $delta < $this->cardinality; $delta++) {
|
||||
if ($delta_callback($delta)) {
|
||||
foreach ($this->columns as $column) {
|
||||
$field_values[$sync_langcode][$delta][$column] = $field_values[$sync_langcode][0][$column];
|
||||
if (in_array($column, $this->synchronized)) {
|
||||
$field_values[$sync_langcode][$delta][$column] = $field_values[$sync_langcode][0][$column];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -209,19 +211,18 @@ class ContentTranslationSyncUnitTest extends KernelTestBase {
|
|||
$changed_items = $field_values[$sync_langcode];
|
||||
$this->synchronizer->synchronizeItems($field_values, $unchanged_items, $sync_langcode, $this->langcodes, $this->synchronized);
|
||||
|
||||
$result = TRUE;
|
||||
foreach ($this->unchangedFieldValues as $langcode => $unchanged_items) {
|
||||
for ($delta = 0; $delta < $this->cardinality; $delta++) {
|
||||
foreach ($this->columns as $column) {
|
||||
// The first item is always unchanged hence it is retained by the
|
||||
// synchronization process. The other ones are retained or synced
|
||||
// depending on the logic implemented by the delta callback.
|
||||
$value = $delta > 0 && $delta_callback($delta) ? $changed_items[0][$column] : $unchanged_items[$delta][$column];
|
||||
$result = $result && ($field_values[$langcode][$delta][$column] == $value);
|
||||
// depending on the logic implemented by the delta callback and
|
||||
// whether it is a sync column or not.
|
||||
$value = $delta > 0 && $delta_callback($delta) && in_array($column, $this->synchronized) ? $changed_items[0][$column] : $unchanged_items[$delta][$column];
|
||||
$this->assertEqual($field_values[$langcode][$delta][$column], $value, "Item $delta column $column for langcode $langcode synced correctly");
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assertTrue($result, 'Multiple synced items have been correctly synchronized.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,15 +242,16 @@ class ContentTranslationSyncUnitTest extends KernelTestBase {
|
|||
$changed_items = $field_values[$sync_langcode];
|
||||
$this->synchronizer->synchronizeItems($field_values, $unchanged_items, $sync_langcode, $this->langcodes, $this->synchronized);
|
||||
|
||||
$result = TRUE;
|
||||
foreach ($this->unchangedFieldValues as $langcode => $unchanged_items) {
|
||||
for ($delta = 0; $delta < $this->cardinality; $delta++) {
|
||||
foreach ($this->columns as $column) {
|
||||
$result = $result && ($field_values[$langcode][$delta][$column] == $changed_items[$delta][$column]);
|
||||
// If the column is synchronized, the value should have been synced,
|
||||
// for unsychronized columns, the value must not change.
|
||||
$expected_value = in_array($column, $this->synchronized) ? $changed_items[$delta][$column] : $this->unchangedFieldValues[$langcode][$delta][$column];
|
||||
$this->assertEqual($field_values[$langcode][$delta][$column], $expected_value, "Differing Item $delta column $column for langcode $langcode synced correctly");
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assertTrue($result, 'Differing synced columns have been correctly synchronized.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue