Issue #2320037 by Gábor Hojtsy: Fixed Non-fieldable entities (with only base fields) cannot be configured translatable, eg. shortcuts.
parent
a222458520
commit
cc87280b47
|
|
@ -94,35 +94,34 @@ function _content_translation_form_language_content_settings_form_alter(array &$
|
||||||
// to be able to skip alterations.
|
// to be able to skip alterations.
|
||||||
$form['settings'][$entity_type_id][$bundle]['settings']['language']['#content_translation_skip_alter'] = TRUE;
|
$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
|
$fields = $entity_manager->getFieldDefinitions($entity_type_id, $bundle);
|
||||||
// entity might have fields and if there are fields to translate.
|
if ($fields) {
|
||||||
if ($entity_type->isFieldable()) {
|
foreach ($fields as $field_name => $definition) {
|
||||||
$fields = $entity_manager->getFieldDefinitions($entity_type_id, $bundle);
|
// Allow to configure only fields supporting multilingual storage.
|
||||||
if ($fields) {
|
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(
|
$form['settings'][$entity_type_id][$bundle]['translatable'] = array(
|
||||||
'#type' => 'checkbox',
|
'#type' => 'checkbox',
|
||||||
'#default_value' => content_translation_enabled($entity_type_id, $bundle),
|
'#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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -173,27 +173,31 @@ abstract class ContentTranslationTestBase extends WebTestBase {
|
||||||
* Creates the test fields.
|
* Creates the test fields.
|
||||||
*/
|
*/
|
||||||
protected function setupTestFields() {
|
protected function setupTestFields() {
|
||||||
$this->fieldName = 'field_test_et_ui_test';
|
$entity_type = \Drupal::entityManager()->getDefinition($this->entityTypeId);
|
||||||
|
if ($entity_type->isFieldable()) {
|
||||||
entity_create('field_storage_config', array(
|
if (empty($this->fieldName)) {
|
||||||
'name' => $this->fieldName,
|
$this->fieldName = 'field_test_et_ui_test';
|
||||||
'type' => 'text',
|
}
|
||||||
'entity_type' => $this->entityTypeId,
|
entity_create('field_storage_config', array(
|
||||||
'cardinality' => 1,
|
'name' => $this->fieldName,
|
||||||
'translatable' => TRUE,
|
'type' => 'text',
|
||||||
))->save();
|
'entity_type' => $this->entityTypeId,
|
||||||
entity_create('field_instance_config', array(
|
'cardinality' => 1,
|
||||||
'entity_type' => $this->entityTypeId,
|
'translatable' => TRUE,
|
||||||
'field_name' => $this->fieldName,
|
))->save();
|
||||||
'bundle' => $this->bundle,
|
entity_create('field_instance_config', array(
|
||||||
'label' => 'Test translatable text-field',
|
'entity_type' => $this->entityTypeId,
|
||||||
))->save();
|
'field_name' => $this->fieldName,
|
||||||
entity_get_form_display($this->entityTypeId, $this->bundle, 'default')
|
'bundle' => $this->bundle,
|
||||||
->setComponent($this->fieldName, array(
|
'label' => 'Test translatable text-field',
|
||||||
'type' => 'text_textfield',
|
))->save();
|
||||||
'weight' => 0,
|
entity_get_form_display($this->entityTypeId, $this->bundle, 'default')
|
||||||
))
|
->setComponent($this->fieldName, array(
|
||||||
->save();
|
'type' => 'text_textfield',
|
||||||
|
'weight' => 0,
|
||||||
|
))
|
||||||
|
->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ class MenuLinkContentUITest extends ContentTranslationUITest {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
$this->entityTypeId = 'menu_link_content';
|
$this->entityTypeId = 'menu_link_content';
|
||||||
$this->bundle = 'menu_link_content';
|
$this->bundle = 'menu_link_content';
|
||||||
$this->fieldName = 'title';
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,3 +12,8 @@ entity.shortcut_set.edit_form:
|
||||||
route_name: entity.shortcut_set.edit_form
|
route_name: entity.shortcut_set.edit_form
|
||||||
base_route: entity.shortcut_set.customize_form
|
base_route: entity.shortcut_set.customize_form
|
||||||
weight: 10
|
weight: 10
|
||||||
|
|
||||||
|
entity.shortcut.canonical:
|
||||||
|
route_name: entity.shortcut.canonical
|
||||||
|
base_route: entity.shortcut.canonical
|
||||||
|
title: Edit
|
||||||
|
|
|
||||||
|
|
@ -279,6 +279,7 @@ function shortcut_renderable_links($shortcut_set = NULL) {
|
||||||
$shortcuts = \Drupal::entityManager()->getStorage('shortcut')->loadByProperties(array('shortcut_set' => $shortcut_set->id()));
|
$shortcuts = \Drupal::entityManager()->getStorage('shortcut')->loadByProperties(array('shortcut_set' => $shortcut_set->id()));
|
||||||
$all_cache_tags = array();
|
$all_cache_tags = array();
|
||||||
foreach ($shortcuts as $shortcut) {
|
foreach ($shortcuts as $shortcut) {
|
||||||
|
$shortcut = \Drupal::entityManager()->getTranslationFromContext($shortcut);
|
||||||
$links[] = array(
|
$links[] = array(
|
||||||
'title' => $shortcut->label(),
|
'title' => $shortcut->label(),
|
||||||
'href' => $shortcut->path->value,
|
'href' => $shortcut->path->value,
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ use Drupal\shortcut\ShortcutSetInterface;
|
||||||
* }
|
* }
|
||||||
* },
|
* },
|
||||||
* config_prefix = "set",
|
* config_prefix = "set",
|
||||||
|
* bundle_of = "shortcut",
|
||||||
* entity_keys = {
|
* entity_keys = {
|
||||||
* "id" = "id",
|
* "id" = "id",
|
||||||
* "label" = "label"
|
* "label" = "label"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Contains \Drupal\shortcut\Tests\ShortcutTranslationUITest.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Drupal\shortcut\Tests;
|
||||||
|
|
||||||
|
use Drupal\content_translation\Tests\ContentTranslationUITest;
|
||||||
|
use Drupal\Core\Language\Language;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the shortcut translation UI.
|
||||||
|
*
|
||||||
|
* @group Shortcut
|
||||||
|
*/
|
||||||
|
class ShortcutTranslationUITest extends ContentTranslationUITest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modules to enable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $modules = array(
|
||||||
|
'language',
|
||||||
|
'content_translation',
|
||||||
|
'shortcut',
|
||||||
|
'toolbar'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() {
|
||||||
|
$this->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('<front>', 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())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue