upgrades core to 8.4.2
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* @file
|
||||
* Menu UI admin behaviors.
|
||||
*/
|
||||
|
||||
(function ($, Drupal) {
|
||||
/**
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*/
|
||||
Drupal.behaviors.menuUiChangeParentItems = {
|
||||
attach(context, settings) {
|
||||
const $menu = $('#edit-menu').once('menu-parent');
|
||||
if ($menu.length) {
|
||||
// Update the list of available parent menu items to match the initial
|
||||
// available menus.
|
||||
Drupal.menuUiUpdateParentList();
|
||||
|
||||
// Update list of available parent menu items.
|
||||
$menu.on('change', 'input', Drupal.menuUiUpdateParentList);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to set the options of the menu parent item dropdown.
|
||||
*/
|
||||
Drupal.menuUiUpdateParentList = function () {
|
||||
const $menu = $('#edit-menu');
|
||||
const values = [];
|
||||
|
||||
$menu.find('input:checked').each(function () {
|
||||
// Get the names of all checked menus.
|
||||
values.push(Drupal.checkPlain($.trim($(this).val())));
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: `${location.protocol}//${location.host}${Drupal.url('admin/structure/menu/parents')}`,
|
||||
type: 'POST',
|
||||
data: { 'menus[]': values },
|
||||
dataType: 'json',
|
||||
success(options) {
|
||||
const $select = $('#edit-menu-parent');
|
||||
// Save key of last selected element.
|
||||
const selected = $select.val();
|
||||
// Remove all existing options from dropdown.
|
||||
$select.children().remove();
|
||||
// Add new options to dropdown. Keep a count of options for testing later.
|
||||
let totalOptions = 0;
|
||||
for (const machineName in options) {
|
||||
if (options.hasOwnProperty(machineName)) {
|
||||
$select.append(
|
||||
$(`<option ${machineName === selected ? ' selected="selected"' : ''}></option>`).val(machineName).text(options[machineName]),
|
||||
);
|
||||
totalOptions++;
|
||||
}
|
||||
}
|
||||
|
||||
// Hide the parent options if there are no options for it.
|
||||
$select.closest('div').toggle(totalOptions > 0).attr('hidden', totalOptions === 0);
|
||||
},
|
||||
});
|
||||
};
|
||||
}(jQuery, Drupal));
|
||||
@@ -1,68 +1,52 @@
|
||||
/**
|
||||
* @file
|
||||
* Menu UI admin behaviors.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, Drupal) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*/
|
||||
Drupal.behaviors.menuUiChangeParentItems = {
|
||||
attach: function (context, settings) {
|
||||
attach: function attach(context, settings) {
|
||||
var $menu = $('#edit-menu').once('menu-parent');
|
||||
if ($menu.length) {
|
||||
// Update the list of available parent menu items to match the initial
|
||||
// available menus.
|
||||
Drupal.menuUiUpdateParentList();
|
||||
|
||||
// Update list of available parent menu items.
|
||||
$menu.on('change', 'input', Drupal.menuUiUpdateParentList);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to set the options of the menu parent item dropdown.
|
||||
*/
|
||||
Drupal.menuUiUpdateParentList = function () {
|
||||
var $menu = $('#edit-menu');
|
||||
var values = [];
|
||||
|
||||
$menu.find('input:checked').each(function () {
|
||||
// Get the names of all checked menus.
|
||||
values.push(Drupal.checkPlain($.trim($(this).val())));
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: location.protocol + '//' + location.host + Drupal.url('admin/structure/menu/parents'),
|
||||
type: 'POST',
|
||||
data: {'menus[]': values},
|
||||
data: { 'menus[]': values },
|
||||
dataType: 'json',
|
||||
success: function (options) {
|
||||
success: function success(options) {
|
||||
var $select = $('#edit-menu-parent');
|
||||
// Save key of last selected element.
|
||||
|
||||
var selected = $select.val();
|
||||
// Remove all existing options from dropdown.
|
||||
|
||||
$select.children().remove();
|
||||
// Add new options to dropdown. Keep a count of options for testing later.
|
||||
|
||||
var totalOptions = 0;
|
||||
for (var machineName in options) {
|
||||
if (options.hasOwnProperty(machineName)) {
|
||||
$select.append(
|
||||
$('<option ' + (machineName === selected ? ' selected="selected"' : '') + '></option>').val(machineName).text(options[machineName])
|
||||
);
|
||||
$select.append($('<option ' + (machineName === selected ? ' selected="selected"' : '') + '></option>').val(machineName).text(options[machineName]));
|
||||
totalOptions++;
|
||||
}
|
||||
}
|
||||
|
||||
// Hide the parent options if there are no options for it.
|
||||
$select.closest('div').toggle(totalOptions > 0).attr('hidden', totalOptions === 0);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
})(jQuery, Drupal);
|
||||
})(jQuery, Drupal);
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* @file
|
||||
* Menu UI behaviors.
|
||||
*/
|
||||
|
||||
(function ($, Drupal) {
|
||||
/**
|
||||
* Set a summary on the menu link form.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Find the form and call `drupalSetSummary` on it.
|
||||
*/
|
||||
Drupal.behaviors.menuUiDetailsSummaries = {
|
||||
attach(context) {
|
||||
$(context).find('.menu-link-form').drupalSetSummary((context) => {
|
||||
const $context = $(context);
|
||||
if ($context.find('.js-form-item-menu-enabled input').is(':checked')) {
|
||||
return Drupal.checkPlain($context.find('.js-form-item-menu-title input').val());
|
||||
}
|
||||
|
||||
return Drupal.t('Not in menu');
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Automatically fill in a menu link title, if possible.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches change and keyup behavior for automatically filling out menu
|
||||
* link titles.
|
||||
*/
|
||||
Drupal.behaviors.menuUiLinkAutomaticTitle = {
|
||||
attach(context) {
|
||||
const $context = $(context);
|
||||
$context.find('.menu-link-form').each(function () {
|
||||
const $this = $(this);
|
||||
// Try to find menu settings widget elements as well as a 'title' field
|
||||
// in the form, but play nicely with user permissions and form
|
||||
// alterations.
|
||||
const $checkbox = $this.find('.js-form-item-menu-enabled input');
|
||||
const $link_title = $context.find('.js-form-item-menu-title input');
|
||||
const $title = $this.closest('form').find('.js-form-item-title-0-value input');
|
||||
// Bail out if we do not have all required fields.
|
||||
if (!($checkbox.length && $link_title.length && $title.length)) {
|
||||
return;
|
||||
}
|
||||
// If there is a link title already, mark it as overridden. The user
|
||||
// expects that toggling the checkbox twice will take over the node's
|
||||
// title.
|
||||
if ($checkbox.is(':checked') && $link_title.val().length) {
|
||||
$link_title.data('menuLinkAutomaticTitleOverridden', true);
|
||||
}
|
||||
// Whenever the value is changed manually, disable this behavior.
|
||||
$link_title.on('keyup', () => {
|
||||
$link_title.data('menuLinkAutomaticTitleOverridden', true);
|
||||
});
|
||||
// Global trigger on checkbox (do not fill-in a value when disabled).
|
||||
$checkbox.on('change', () => {
|
||||
if ($checkbox.is(':checked')) {
|
||||
if (!$link_title.data('menuLinkAutomaticTitleOverridden')) {
|
||||
$link_title.val($title.val());
|
||||
}
|
||||
}
|
||||
else {
|
||||
$link_title.val('');
|
||||
$link_title.removeData('menuLinkAutomaticTitleOverridden');
|
||||
}
|
||||
$checkbox.closest('.vertical-tabs-pane').trigger('summaryUpdated');
|
||||
$checkbox.trigger('formUpdated');
|
||||
});
|
||||
// Take over any title change.
|
||||
$title.on('keyup', () => {
|
||||
if (!$link_title.data('menuLinkAutomaticTitleOverridden') && $checkbox.is(':checked')) {
|
||||
$link_title.val($title.val());
|
||||
$link_title.val($title.val()).trigger('formUpdated');
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
}(jQuery, Drupal));
|
||||
@@ -8,8 +8,8 @@ configure: entity.menu.collection
|
||||
dependencies:
|
||||
- menu_link_content
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1502903957
|
||||
datestamp: 1509719929
|
||||
|
||||
@@ -1,83 +1,59 @@
|
||||
/**
|
||||
* @file
|
||||
* Menu UI behaviors.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, Drupal) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Set a summary on the menu link form.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Find the form and call `drupalSetSummary` on it.
|
||||
*/
|
||||
Drupal.behaviors.menuUiDetailsSummaries = {
|
||||
attach: function (context) {
|
||||
attach: function attach(context) {
|
||||
$(context).find('.menu-link-form').drupalSetSummary(function (context) {
|
||||
var $context = $(context);
|
||||
if ($context.find('.js-form-item-menu-enabled input').is(':checked')) {
|
||||
return Drupal.checkPlain($context.find('.js-form-item-menu-title input').val());
|
||||
}
|
||||
else {
|
||||
return Drupal.t('Not in menu');
|
||||
}
|
||||
|
||||
return Drupal.t('Not in menu');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Automatically fill in a menu link title, if possible.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches change and keyup behavior for automatically filling out menu
|
||||
* link titles.
|
||||
*/
|
||||
Drupal.behaviors.menuUiLinkAutomaticTitle = {
|
||||
attach: function (context) {
|
||||
attach: function attach(context) {
|
||||
var $context = $(context);
|
||||
$context.find('.menu-link-form').each(function () {
|
||||
var $this = $(this);
|
||||
// Try to find menu settings widget elements as well as a 'title' field
|
||||
// in the form, but play nicely with user permissions and form
|
||||
// alterations.
|
||||
|
||||
var $checkbox = $this.find('.js-form-item-menu-enabled input');
|
||||
var $link_title = $context.find('.js-form-item-menu-title input');
|
||||
var $title = $this.closest('form').find('.js-form-item-title-0-value input');
|
||||
// Bail out if we do not have all required fields.
|
||||
|
||||
if (!($checkbox.length && $link_title.length && $title.length)) {
|
||||
return;
|
||||
}
|
||||
// If there is a link title already, mark it as overridden. The user
|
||||
// expects that toggling the checkbox twice will take over the node's
|
||||
// title.
|
||||
|
||||
if ($checkbox.is(':checked') && $link_title.val().length) {
|
||||
$link_title.data('menuLinkAutomaticTitleOverridden', true);
|
||||
}
|
||||
// Whenever the value is changed manually, disable this behavior.
|
||||
|
||||
$link_title.on('keyup', function () {
|
||||
$link_title.data('menuLinkAutomaticTitleOverridden', true);
|
||||
});
|
||||
// Global trigger on checkbox (do not fill-in a value when disabled).
|
||||
|
||||
$checkbox.on('change', function () {
|
||||
if ($checkbox.is(':checked')) {
|
||||
if (!$link_title.data('menuLinkAutomaticTitleOverridden')) {
|
||||
$link_title.val($title.val());
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$link_title.val('');
|
||||
$link_title.removeData('menuLinkAutomaticTitleOverridden');
|
||||
}
|
||||
$checkbox.closest('.vertical-tabs-pane').trigger('summaryUpdated');
|
||||
$checkbox.trigger('formUpdated');
|
||||
});
|
||||
// Take over any title change.
|
||||
|
||||
$title.on('keyup', function () {
|
||||
if (!$link_title.data('menuLinkAutomaticTitleOverridden') && $checkbox.is(':checked')) {
|
||||
$link_title.val($title.val());
|
||||
@@ -87,5 +63,4 @@
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery, Drupal);
|
||||
})(jQuery, Drupal);
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
use Drupal\Core\Breadcrumb\Breadcrumb;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Block\BlockPluginInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Menu\MenuLinkInterface;
|
||||
@@ -27,6 +26,8 @@ use Drupal\node\NodeInterface;
|
||||
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\Core\Config\Entity\ConfigEntityStorage::MAX_ID_LENGTH because the
|
||||
* menu name is a configuration entity ID.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2831620
|
||||
*/
|
||||
const MENU_MAX_MENU_NAME_LENGTH_UI = 27;
|
||||
|
||||
@@ -71,6 +72,10 @@ function menu_ui_entity_type_build(array &$entity_types) {
|
||||
->setLinkTemplate('edit-form', '/admin/structure/menu/manage/{menu}')
|
||||
->setLinkTemplate('add-link-form', '/admin/structure/menu/manage/{menu}/add')
|
||||
->setLinkTemplate('collection', '/admin/structure/menu');
|
||||
|
||||
if (isset($entity_types['node'])) {
|
||||
$entity_types['node']->addConstraint('MenuSettings', []);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,24 +171,6 @@ function _menu_ui_node_save(NodeInterface $node, array $values) {
|
||||
$entity->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ENTITY_TYPE_predelete() for node entities.
|
||||
*/
|
||||
function menu_ui_node_predelete(EntityInterface $node) {
|
||||
// Delete all MenuLinkContent links that point to this node.
|
||||
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
|
||||
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
|
||||
$result = $menu_link_manager->loadLinksByRoute('entity.node.canonical', ['node' => $node->id()]);
|
||||
|
||||
if (!empty($result)) {
|
||||
foreach ($result as $id => $instance) {
|
||||
if ($instance->isDeletable() && strpos($id, 'menu_link_content:') === 0) {
|
||||
$instance->deleteLink();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the definition for a menu link for the given node.
|
||||
*
|
||||
@@ -357,6 +344,15 @@ function menu_ui_form_node_form_alter(&$form, FormStateInterface $form_state) {
|
||||
$form['actions'][$action]['#submit'][] = 'menu_ui_form_node_form_submit';
|
||||
}
|
||||
}
|
||||
|
||||
$form['#entity_builders'][] = 'menu_ui_node_builder';
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity form builder to add the menu information to the node.
|
||||
*/
|
||||
function menu_ui_node_builder($entity_type, NodeInterface $entity, &$form, FormStateInterface $form_state) {
|
||||
$entity->menu = $form_state->getValue('menu');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,7 @@ source:
|
||||
plugin: variable
|
||||
variables:
|
||||
- menu_override_parent_selector
|
||||
source_module: menu
|
||||
process:
|
||||
override_parent_selector: menu_override_parent_selector
|
||||
destination:
|
||||
|
||||
@@ -221,7 +221,7 @@ class MenuForm extends EntityForm {
|
||||
$this->getRequest()->attributes->set('_menu_admin', FALSE);
|
||||
|
||||
// Determine the delta; the number of weights to be made available.
|
||||
$count = function(array $tree) {
|
||||
$count = function (array $tree) {
|
||||
$sum = function ($carry, MenuLinkTreeElement $item) {
|
||||
return $carry + $item->count();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\menu_ui\Plugin\Validation\Constraint;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
/**
|
||||
* Validation constraint for changing the menu settings in pending revisions.
|
||||
*
|
||||
* @Constraint(
|
||||
* id = "MenuSettings",
|
||||
* label = @Translation("Menu settings.", context = "Validation"),
|
||||
* )
|
||||
*/
|
||||
class MenuSettingsConstraint extends Constraint {
|
||||
|
||||
public $message = 'You can only change the menu settings for the <em>published</em> version of this content.';
|
||||
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\menu_ui\Plugin\Validation\Constraint;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
/**
|
||||
* Constraint validator for changing the menu settings in pending revisions.
|
||||
*/
|
||||
class MenuSettingsConstraintValidator extends ConstraintValidator {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate($entity, Constraint $constraint) {
|
||||
if (isset($entity) && !$entity->isNew() && !$entity->isDefaultRevision()) {
|
||||
$defaults = menu_ui_get_menu_link_defaults($entity);
|
||||
$values = $entity->menu;
|
||||
$violation_path = NULL;
|
||||
|
||||
if (trim($values['title']) && !empty($values['menu_parent'])) {
|
||||
list($menu_name, $parent) = explode(':', $values['menu_parent'], 2);
|
||||
$values['menu_name'] = $menu_name;
|
||||
$values['parent'] = $parent;
|
||||
}
|
||||
|
||||
// Handle the case when a menu link is added to a pending revision.
|
||||
if (!$defaults['entity_id'] && $values['enabled']) {
|
||||
$violation_path = 'menu';
|
||||
}
|
||||
// Handle the case when the menu link is deleted in a pending revision.
|
||||
elseif (empty($values['enabled']) && $defaults['entity_id']) {
|
||||
$violation_path = 'menu';
|
||||
}
|
||||
// Handle all the other menu link changes in a pending revision.
|
||||
elseif ($defaults['entity_id']) {
|
||||
if (($values['title'] != $defaults['title'])) {
|
||||
$violation_path = 'menu.title';
|
||||
}
|
||||
elseif (($values['description'] != $defaults['description'])) {
|
||||
$violation_path = 'menu.description';
|
||||
}
|
||||
elseif ($defaults['entity_id'] && ($values['menu_name'] != $defaults['menu_name'])) {
|
||||
$violation_path = 'menu.menu_parent';
|
||||
}
|
||||
elseif (isset($values['parent']) && ($values['parent'] != $defaults['parent'])) {
|
||||
$violation_path = 'menu.menu_parent';
|
||||
}
|
||||
elseif (($values['weight'] != $defaults['weight'])) {
|
||||
$violation_path = 'menu.weight';
|
||||
}
|
||||
}
|
||||
|
||||
if ($violation_path) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->atPath($violation_path)
|
||||
->setInvalidValue($entity)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -134,8 +134,7 @@ class MenuNodeTest extends WebTestBase {
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertNoLink($node_title);
|
||||
|
||||
// Use not only the save button, but also the two special buttons:
|
||||
// 'Save and publish' as well as 'Save and keep published'.
|
||||
// Make sure the menu links only appear when the node is published.
|
||||
// These buttons just appear for 'administer nodes' users.
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'access administration pages',
|
||||
@@ -146,21 +145,20 @@ class MenuNodeTest extends WebTestBase {
|
||||
'edit any page content',
|
||||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
foreach (['Save and unpublish' => FALSE, 'Save and keep unpublished' => FALSE, 'Save and publish' => TRUE, 'Save and keep published' => TRUE] as $submit => $visible) {
|
||||
$edit = [
|
||||
'menu[enabled]' => 1,
|
||||
'menu[title]' => $node_title,
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, $submit);
|
||||
// Assert that the link exists.
|
||||
$this->drupalGet('test-page');
|
||||
if ($visible) {
|
||||
$this->assertLink($node_title, 0, 'Found a menu link after submitted with ' . $submit);
|
||||
}
|
||||
else {
|
||||
$this->assertNoLink($node_title, 'Found no menu link after submitted with ' . $submit);
|
||||
}
|
||||
}
|
||||
// Assert that the link does not exist if unpublished.
|
||||
$edit = [
|
||||
'menu[enabled]' => 1,
|
||||
'menu[title]' => $node_title,
|
||||
'status[value]' => FALSE,
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save');
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertNoLink($node_title, 'Found no menu link with the node unpublished');
|
||||
// Assert that the link exists if published.
|
||||
$edit['status[value]'] = TRUE;
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save');
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertLink($node_title, 0, 'Found a menu link with the node published');
|
||||
|
||||
// Log back in as normal user.
|
||||
$this->drupalLogin($this->editor);
|
||||
|
||||
@@ -82,9 +82,9 @@ class MenuCacheTagsTest extends PageCacheTagsTestBase {
|
||||
'parent' => '',
|
||||
'title' => 'Alpaca',
|
||||
'menu_name' => 'llama',
|
||||
'link' => [[
|
||||
'uri' => 'internal:/',
|
||||
]],
|
||||
'link' => [
|
||||
['uri' => 'internal:/'],
|
||||
],
|
||||
'bundle' => 'menu_name',
|
||||
]);
|
||||
$menu_link_2->save();
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\menu_ui\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\workflows\Entity\Workflow;
|
||||
|
||||
/**
|
||||
* Tests Menu UI and Content Moderation integration.
|
||||
*
|
||||
* @group menu_ui
|
||||
*/
|
||||
class MenuUiContentModerationTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'content_moderation', 'node', 'menu_ui', 'test_page_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('system_menu_block:main');
|
||||
|
||||
// Create a 'page' content type.
|
||||
$this->drupalCreateContentType([
|
||||
'type' => 'page',
|
||||
'name' => 'Basic page',
|
||||
'display_submitted' => FALSE,
|
||||
]);
|
||||
|
||||
$workflow = Workflow::load('editorial');
|
||||
$workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
|
||||
$workflow->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that node drafts can not modify the menu settings.
|
||||
*/
|
||||
public function testMenuUiWithPendingRevisions() {
|
||||
$editor = $this->drupalCreateUser([
|
||||
'administer nodes',
|
||||
'administer menu',
|
||||
'create page content',
|
||||
'edit any page content',
|
||||
'use editorial transition create_new_draft',
|
||||
'use editorial transition publish',
|
||||
'view latest version',
|
||||
'view any unpublished content',
|
||||
]);
|
||||
$this->drupalLogin($editor);
|
||||
|
||||
// Create a node.
|
||||
$node = $this->drupalCreateNode();
|
||||
|
||||
// Publish the node with no changes.
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save'));
|
||||
$this->assertSession()->responseContains(t('Page %label has been updated.', ['%label' => $node->toLink($node->label())->toString()]));
|
||||
|
||||
// Create a pending revision with no changes.
|
||||
$edit = ['moderation_state[0][state]' => 'draft'];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
$this->assertSession()->responseContains(t('Page %label has been updated.', ['%label' => $node->toLink($node->label())->toString()]));
|
||||
|
||||
// Add a menu link and save a new default (published) revision.
|
||||
$edit = [
|
||||
'menu[enabled]' => 1,
|
||||
'menu[title]' => 'Test menu link',
|
||||
'moderation_state[0][state]' => 'published',
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
|
||||
$this->assertSession()->linkExists('Test menu link');
|
||||
|
||||
// Try to change the menu link title and save a new non-default (draft)
|
||||
// revision.
|
||||
$edit = [
|
||||
'menu[title]' => 'Test menu link draft',
|
||||
'moderation_state[0][state]' => 'draft',
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
|
||||
// Check that the menu settings were not applied.
|
||||
$this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
|
||||
$this->assertSession()->linkExists('Test menu link');
|
||||
$this->assertSession()->linkNotExists('Test menu link draft');
|
||||
|
||||
// Try to change the menu link description and save a new non-default
|
||||
// (draft) revision.
|
||||
$edit = [
|
||||
'menu[description]' => 'Test menu link description',
|
||||
'moderation_state[0][state]' => 'draft',
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
|
||||
// Check that the menu settings were not applied.
|
||||
$this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
|
||||
|
||||
// Try to change the menu link weight and save a new non-default (draft)
|
||||
// revision.
|
||||
$edit = [
|
||||
'menu[weight]' => 1,
|
||||
'moderation_state[0][state]' => 'draft',
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
|
||||
// Check that the menu settings were not applied.
|
||||
$this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
|
||||
|
||||
// Try to change the menu link parent and save a new non-default (draft)
|
||||
// revision.
|
||||
$edit = [
|
||||
'menu[menu_parent]' => 'main:test_page_test.front_page',
|
||||
'moderation_state[0][state]' => 'draft',
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
|
||||
// Check that the menu settings were not applied.
|
||||
$this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
|
||||
|
||||
// Try to delete the menu link and save a new non-default (draft) revision.
|
||||
$edit = [
|
||||
'menu[enabled]' => 0,
|
||||
'moderation_state[0][state]' => 'draft',
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
|
||||
// Check that the menu settings were not applied.
|
||||
$this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
|
||||
$this->assertSession()->linkExists('Test menu link');
|
||||
|
||||
// Try to save a new non-default (draft) revision without any changes and
|
||||
// check that the error message is not shown.
|
||||
$edit = ['moderation_state[0][state]' => 'draft'];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
|
||||
// Check that the menu settings were not applied.
|
||||
$this->assertSession()->pageTextNotContains('You can only change the menu settings for the published version of this content.');
|
||||
$this->assertSession()->linkExists('Test menu link');
|
||||
|
||||
// Create a node.
|
||||
$node = $this->drupalCreateNode();
|
||||
|
||||
// Publish the node with no changes.
|
||||
$edit = ['moderation_state[0][state]' => 'published'];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
$this->assertSession()->responseContains(t('Page %label has been updated.', ['%label' => $node->toLink($node->label())->toString()]));
|
||||
|
||||
// Add a menu link and save and create a new non-default (draft) revision.
|
||||
$edit = [
|
||||
'menu[enabled]' => 1,
|
||||
'menu[title]' => 'Test menu link',
|
||||
'moderation_state[0][state]' => 'draft',
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
$this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user