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,16 +94,8 @@ 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) {
|
||||
$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()) {
|
||||
|
|
@ -123,6 +115,13 @@ function _content_translation_form_language_content_settings_form_alter(array &$
|
|||
}
|
||||
}
|
||||
}
|
||||
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),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,8 +173,11 @@ abstract class ContentTranslationTestBase extends WebTestBase {
|
|||
* Creates the test fields.
|
||||
*/
|
||||
protected function setupTestFields() {
|
||||
$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',
|
||||
|
|
@ -195,6 +198,7 @@ abstract class ContentTranslationTestBase extends WebTestBase {
|
|||
))
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the entity to be translated.
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ use Drupal\shortcut\ShortcutSetInterface;
|
|||
* }
|
||||
* },
|
||||
* config_prefix = "set",
|
||||
* bundle_of = "shortcut",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "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