From cc87280b47abe0900807419ccbbf837a6ece86b4 Mon Sep 17 00:00:00 2001 From: webchick Date: Wed, 3 Sep 2014 08:34:18 -0700 Subject: [PATCH] =?UTF-8?q?Issue=20#2320037=20by=20G=C3=A1bor=20Hojtsy:=20?= =?UTF-8?q?Fixed=20Non-fieldable=20entities=20(with=20only=20base=20fields?= =?UTF-8?q?)=20cannot=20be=20configured=20translatable,=20eg.=20shortcuts.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../content_translation.admin.inc | 49 ++++++------ .../src/Tests/ContentTranslationTestBase.php | 46 ++++++------ .../src/Tests/MenuLinkContentUITest.php | 1 - core/modules/shortcut/shortcut.links.task.yml | 5 ++ core/modules/shortcut/shortcut.module | 1 + .../shortcut/src/Entity/ShortcutSet.php | 1 + .../src/Tests/ShortcutTranslationUITest.php | 75 +++++++++++++++++++ 7 files changed, 131 insertions(+), 47 deletions(-) create mode 100644 core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 7fc13b2c4f65..529a32594d74 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -94,35 +94,34 @@ function _content_translation_form_language_content_settings_form_alter(array &$ // to be able to skip alterations. $form['settings'][$entity_type_id][$bundle]['settings']['language']['#content_translation_skip_alter'] = TRUE; - // Only show the checkbox to enable translation if the bundles in the - // entity might have fields and if there are fields to translate. - if ($entity_type->isFieldable()) { - $fields = $entity_manager->getFieldDefinitions($entity_type_id, $bundle); - if ($fields) { + $fields = $entity_manager->getFieldDefinitions($entity_type_id, $bundle); + if ($fields) { + foreach ($fields as $field_name => $definition) { + // Allow to configure only fields supporting multilingual storage. + if (!empty($storage_definitions[$field_name]) && $storage_definitions[$field_name]->isTranslatable()) { + $form['settings'][$entity_type_id][$bundle]['fields'][$field_name] = array( + '#label' => $definition->getLabel(), + '#type' => 'checkbox', + '#default_value' => $definition->isTranslatable(), + ); + // Display the column translatability configuration widget. + $column_element = content_translation_field_sync_widget($definition); + 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'); + } + } + } + } + if (!empty($form['settings'][$entity_type_id][$bundle]['fields'])) { + // Only show the checkbox to enable translation if the bundles in the + // entity might have fields and if there are fields to translate. $form['settings'][$entity_type_id][$bundle]['translatable'] = array( '#type' => 'checkbox', '#default_value' => content_translation_enabled($entity_type_id, $bundle), ); - - foreach ($fields as $field_name => $definition) { - // Allow to configure only fields supporting multilingual storage. - if (!empty($storage_definitions[$field_name]) && $storage_definitions[$field_name]->isTranslatable()) { - $form['settings'][$entity_type_id][$bundle]['fields'][$field_name] = array( - '#label' => $definition->getLabel(), - '#type' => 'checkbox', - '#default_value' => $definition->isTranslatable(), - ); - // Display the column translatability configuration widget. - $column_element = content_translation_field_sync_widget($definition); - 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'); - } - } - } - } } } } diff --git a/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php b/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php index 81de3aa798bc..d8310452fb7e 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php @@ -173,27 +173,31 @@ abstract class ContentTranslationTestBase extends WebTestBase { * Creates the test fields. */ protected function setupTestFields() { - $this->fieldName = 'field_test_et_ui_test'; - - entity_create('field_storage_config', array( - 'name' => $this->fieldName, - 'type' => 'text', - 'entity_type' => $this->entityTypeId, - 'cardinality' => 1, - 'translatable' => TRUE, - ))->save(); - entity_create('field_instance_config', array( - 'entity_type' => $this->entityTypeId, - 'field_name' => $this->fieldName, - 'bundle' => $this->bundle, - 'label' => 'Test translatable text-field', - ))->save(); - entity_get_form_display($this->entityTypeId, $this->bundle, 'default') - ->setComponent($this->fieldName, array( - 'type' => 'text_textfield', - 'weight' => 0, - )) - ->save(); + $entity_type = \Drupal::entityManager()->getDefinition($this->entityTypeId); + if ($entity_type->isFieldable()) { + if (empty($this->fieldName)) { + $this->fieldName = 'field_test_et_ui_test'; + } + entity_create('field_storage_config', array( + 'name' => $this->fieldName, + 'type' => 'text', + 'entity_type' => $this->entityTypeId, + 'cardinality' => 1, + 'translatable' => TRUE, + ))->save(); + entity_create('field_instance_config', array( + 'entity_type' => $this->entityTypeId, + 'field_name' => $this->fieldName, + 'bundle' => $this->bundle, + 'label' => 'Test translatable text-field', + ))->save(); + entity_get_form_display($this->entityTypeId, $this->bundle, 'default') + ->setComponent($this->fieldName, array( + 'type' => 'text_textfield', + 'weight' => 0, + )) + ->save(); + } } /** diff --git a/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php b/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php index 8d2c1f74e764..3a3e027f96bc 100644 --- a/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php +++ b/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php @@ -34,7 +34,6 @@ class MenuLinkContentUITest extends ContentTranslationUITest { protected function setUp() { $this->entityTypeId = 'menu_link_content'; $this->bundle = 'menu_link_content'; - $this->fieldName = 'title'; parent::setUp(); } diff --git a/core/modules/shortcut/shortcut.links.task.yml b/core/modules/shortcut/shortcut.links.task.yml index b9f8bc2d5513..d42c46ebb9ae 100644 --- a/core/modules/shortcut/shortcut.links.task.yml +++ b/core/modules/shortcut/shortcut.links.task.yml @@ -12,3 +12,8 @@ entity.shortcut_set.edit_form: route_name: entity.shortcut_set.edit_form base_route: entity.shortcut_set.customize_form weight: 10 + +entity.shortcut.canonical: + route_name: entity.shortcut.canonical + base_route: entity.shortcut.canonical + title: Edit diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index b705ebfaa98e..be1d027d8a86 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -279,6 +279,7 @@ function shortcut_renderable_links($shortcut_set = NULL) { $shortcuts = \Drupal::entityManager()->getStorage('shortcut')->loadByProperties(array('shortcut_set' => $shortcut_set->id())); $all_cache_tags = array(); foreach ($shortcuts as $shortcut) { + $shortcut = \Drupal::entityManager()->getTranslationFromContext($shortcut); $links[] = array( 'title' => $shortcut->label(), 'href' => $shortcut->path->value, diff --git a/core/modules/shortcut/src/Entity/ShortcutSet.php b/core/modules/shortcut/src/Entity/ShortcutSet.php index a9fc866a0ba3..da603780eae8 100644 --- a/core/modules/shortcut/src/Entity/ShortcutSet.php +++ b/core/modules/shortcut/src/Entity/ShortcutSet.php @@ -30,6 +30,7 @@ use Drupal\shortcut\ShortcutSetInterface; * } * }, * config_prefix = "set", + * bundle_of = "shortcut", * entity_keys = { * "id" = "id", * "label" = "label" diff --git a/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php b/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php new file mode 100644 index 000000000000..1627b60fcffa --- /dev/null +++ b/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php @@ -0,0 +1,75 @@ +entityTypeId = 'shortcut'; + $this->bundle = 'default'; + $this->fieldName = 'title'; + parent::setUp(); + } + + /** + * {@inheritdoc} + */ + protected function getTranslatorPermissions() { + return array_merge(parent::getTranslatorPermissions(), array('access shortcuts', 'administer shortcuts', 'access toolbar')); + } + + /** + * {@inheritdoc} + */ + protected function createEntity($values, $langcode, $bundle_name = NULL) { + $values['route_name'] = 'user.page'; + return parent::createEntity($values, $langcode, $bundle_name); + } + + protected function doTestBasicTranslation() { + parent::doTestBasicTranslation(); + + $entity = entity_load($this->entityTypeId, $this->entityId, TRUE); + foreach ($this->langcodes as $langcode) { + if ($entity->hasTranslation($langcode)) { + $language = new Language(array('id' => $langcode)); + // Request the front page in this language and assert that the right + // translation shows up in the shortcut list with the right path. + $this->drupalGet('', array('language' => $language)); + $expected_path = \Drupal::urlGenerator()->generateFromRoute('user.page', array(), array('language' => $language)); + $label = $entity->getTranslation($langcode)->label(); + $elements = $this->xpath('//nav[contains(@class, "toolbar-lining")]/ul[@class="menu"]/li/a[contains(@href, :href) and normalize-space(text())=:label]', array(':href' => $expected_path, ':label' => $label)); + $this->assertTrue(!empty($elements), format_string('Translated @language shortcut link @label found.', array('@label' => $label, '@language' => $language->getName()))); + } + } + } + +}