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
|
@ -139,12 +139,20 @@ function _menu_ui_node_save(NodeInterface $node, array $values) {
|
|||
/** @var \Drupal\menu_link_content\MenuLinkContentInterface $entity */
|
||||
if (!empty($values['entity_id'])) {
|
||||
$entity = MenuLinkContent::load($values['entity_id']);
|
||||
if ($entity->isTranslatable()) {
|
||||
if (!$entity->hasTranslation($node->language()->getId())) {
|
||||
$entity = $entity->addTranslation($node->language()->getId(), $entity->toArray());
|
||||
}
|
||||
else {
|
||||
$entity = $entity->getTranslation($node->language()->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Create a new menu_link_content entity.
|
||||
$entity = entity_create('menu_link_content', array(
|
||||
'link' => ['uri' => 'entity:node/' . $node->id()],
|
||||
'langcode' => $node->getUntranslated()->language()->getId(),
|
||||
'langcode' => $node->language()->getId(),
|
||||
));
|
||||
$entity->enabled->value = 1;
|
||||
}
|
||||
|
@ -216,10 +224,12 @@ function menu_ui_get_menu_link_defaults(NodeInterface $node) {
|
|||
}
|
||||
if ($id) {
|
||||
$menu_link = MenuLinkContent::load($id);
|
||||
$menu_link = \Drupal::service('entity.repository')->getTranslationFromContext($menu_link);
|
||||
$defaults = array(
|
||||
'entity_id' => $menu_link->id(),
|
||||
'id' => $menu_link->getPluginId(),
|
||||
'title' => $menu_link->getTitle(),
|
||||
'title_max_length' => $menu_link->getFieldDefinitions()['title']->getSetting('max_length'),
|
||||
'description' => $menu_link->getDescription(),
|
||||
'menu_name' => $menu_link->getMenuName(),
|
||||
'parent' => $menu_link->getParentId(),
|
||||
|
@ -229,10 +239,15 @@ function menu_ui_get_menu_link_defaults(NodeInterface $node) {
|
|||
}
|
||||
|
||||
if (!$defaults) {
|
||||
// Get the default max_length of a menu link title from the base field
|
||||
// definition.
|
||||
$field_definitions = \Drupal::entityManager()->getBaseFieldDefinitions('menu_link_content');
|
||||
$max_length = $field_definitions['title']->getSetting('max_length');
|
||||
$defaults = array(
|
||||
'entity_id' => 0,
|
||||
'id' => '',
|
||||
'title' => '',
|
||||
'title_max_length' => $max_length,
|
||||
'description' => '',
|
||||
'menu_name' => $menu_name,
|
||||
'parent' => '',
|
||||
|
@ -313,6 +328,7 @@ function menu_ui_form_node_form_alter(&$form, FormStateInterface $form_state) {
|
|||
'#type' => 'textfield',
|
||||
'#title' => t('Menu link title'),
|
||||
'#default_value' => $defaults['title'],
|
||||
'#maxlength' => $defaults['title_max_length'],
|
||||
);
|
||||
|
||||
$form['menu']['link']['description'] = array(
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
namespace Drupal\menu_ui\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
||||
use Drupal\node\Entity\Node;
|
||||
|
||||
/**
|
||||
* Add, edit, and delete a node with menu link.
|
||||
|
@ -29,7 +31,7 @@ class MenuNodeTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('menu_ui', 'test_page_test', 'node', 'block');
|
||||
public static $modules = array('menu_ui', 'test_page_test', 'node', 'block', 'locale', 'language', 'content_translation');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
@ -46,6 +48,10 @@ class MenuNodeTest extends WebTestBase {
|
|||
'create page content',
|
||||
'edit any page content',
|
||||
'delete any page content',
|
||||
'create content translations',
|
||||
'update content translations',
|
||||
'delete content translations',
|
||||
'translate any entity',
|
||||
));
|
||||
$this->drupalLogin($this->editor);
|
||||
}
|
||||
|
@ -61,6 +67,11 @@ class MenuNodeTest extends WebTestBase {
|
|||
$this->drupalGet('admin/structure/types/manage/page');
|
||||
$this->assertCacheContext('user.roles:authenticated');
|
||||
|
||||
// Verify that the menu link title has the correct maxlength.
|
||||
$max_length = \Drupal::entityManager()->getBaseFieldDefinitions('menu_link_content')['title']->getSetting('max_length');
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertPattern('/<input .* id="edit-menu-title" .* maxlength="' . $max_length . '" .* \/>/', 'Menu link title field has correct maxlength in node add form.');
|
||||
|
||||
// Disable the default main menu, so that no menus are enabled.
|
||||
$edit = array(
|
||||
'menu_options[main]' => FALSE,
|
||||
|
@ -171,6 +182,7 @@ class MenuNodeTest extends WebTestBase {
|
|||
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
$this->assertFieldById('edit-menu-weight', 17, 'Menu weight correct in edit form');
|
||||
$this->assertPattern('/<input .* id="edit-menu-title" .* maxlength="' . $max_length . '" .* \/>/', 'Menu link title field has correct maxlength in node edit form.');
|
||||
|
||||
// Disable the menu link, then edit the node--the link should stay disabled.
|
||||
$link_id = menu_ui_get_menu_link_defaults($node)['entity_id'];
|
||||
|
@ -229,4 +241,105 @@ class MenuNodeTest extends WebTestBase {
|
|||
// Assert that unallowed Administration menu is not available in options.
|
||||
$this->assertNoOption('edit-menu-menu-parent', 'admin:');
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing correct loading and saving of menu links via node form widget in a multilingual environment.
|
||||
*/
|
||||
function testMultilingualMenuNodeFormWidget() {
|
||||
// Setup languages.
|
||||
$langcodes = array('de');
|
||||
foreach ($langcodes as $langcode) {
|
||||
ConfigurableLanguage::createFromLangcode($langcode)->save();
|
||||
}
|
||||
array_unshift($langcodes, \Drupal::languageManager()->getDefaultLanguage()->getId());
|
||||
|
||||
$config = \Drupal::service('config.factory')->getEditable('language.negotiation');
|
||||
// Ensure path prefix is used to determine the language.
|
||||
$config->set('url.source', 'path_prefix');
|
||||
// Ensure that there's a path prefix set for english as well.
|
||||
$config->set('url.prefixes.' . $langcodes[0], $langcodes[0]);
|
||||
$config->save();
|
||||
|
||||
$this->rebuildContainer();
|
||||
|
||||
$languages = array();
|
||||
foreach ($langcodes as $langcode) {
|
||||
$languages[$langcode] = ConfigurableLanguage::load($langcode);
|
||||
}
|
||||
|
||||
// Use a UI form submission to make the node type and menu link content entity translatable.
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($this->rootUser);
|
||||
$edit = array(
|
||||
'entity_types[node]' => TRUE,
|
||||
'entity_types[menu_link_content]' => TRUE,
|
||||
'settings[node][page][settings][language][language_alterable]' => TRUE,
|
||||
'settings[node][page][translatable]' => TRUE,
|
||||
'settings[node][page][fields][title]' => TRUE,
|
||||
'settings[menu_link_content][menu_link_content][translatable]' => TRUE,
|
||||
);
|
||||
$this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
|
||||
|
||||
// Log out and back in as normal user.
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($this->editor);
|
||||
|
||||
// Create a node.
|
||||
$node_title = $this->randomMachineName(8);
|
||||
$node = Node::create([
|
||||
'type' => 'page',
|
||||
'title' => $node_title,
|
||||
'body' => $this->randomMachineName(16),
|
||||
'uid' => $this->editor->id(),
|
||||
'status' => 1,
|
||||
'langcode' => $langcodes[0],
|
||||
]);
|
||||
$node->save();
|
||||
|
||||
// Create translation.
|
||||
$translated_node_title = $this->randomMachineName(8);
|
||||
$node->addTranslation($langcodes[1], ['title' => $translated_node_title, 'body' => $this->randomMachineName(16), 'status' => 1]);
|
||||
$node->save();
|
||||
|
||||
// Edit the node and create a menu link.
|
||||
$edit = array(
|
||||
'menu[enabled]' => 1,
|
||||
'menu[title]' => $node_title,
|
||||
'menu[weight]' => 17,
|
||||
);
|
||||
$options = array('language' => $languages[$langcodes[0]]);
|
||||
$url = $node->toUrl('edit-form', $options);
|
||||
$this->drupalPostForm($url, $edit, t('Save') . ' ' . t('(this translation)'));
|
||||
|
||||
// Edit the node in a different language and translate the menu link.
|
||||
$edit = array(
|
||||
'menu[enabled]' => 1,
|
||||
'menu[title]' => $translated_node_title,
|
||||
'menu[weight]' => 17,
|
||||
);
|
||||
$options = array('language' => $languages[$langcodes[1]]);
|
||||
$url = $node->toUrl('edit-form', $options);
|
||||
$this->drupalPostForm($url, $edit, t('Save') . ' ' . t('(this translation)'));
|
||||
|
||||
// Assert that the original link exists in the frontend.
|
||||
$this->drupalGet('node/' . $node->id(), array('language' => $languages[$langcodes[0]]));
|
||||
$this->assertLink($node_title);
|
||||
|
||||
// Assert that the translated link exists in the frontend.
|
||||
$this->drupalGet('node/' . $node->id(), array('language' => $languages[$langcodes[1]]));
|
||||
$this->assertLink($translated_node_title);
|
||||
|
||||
// Revisit the edit page in original language, check the loaded menu item title and save.
|
||||
$options = array('language' => $languages[$langcodes[0]]);
|
||||
$url = $node->toUrl('edit-form', $options);
|
||||
$this->drupalGet($url);
|
||||
$this->assertFieldById('edit-menu-title', $node_title);
|
||||
$this->drupalPostForm(NULL, [], t('Save') . ' ' . t('(this translation)'));
|
||||
|
||||
// Revisit the edit page of the translation and check the loaded menu item title.
|
||||
$options = array('language' => $languages[$langcodes[1]]);
|
||||
$url = $node->toUrl('edit-form', $options);
|
||||
$this->drupalGet($url);
|
||||
$this->assertFieldById('edit-menu-title', $translated_node_title);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue