Issue #2423153 by idebr, dawehner, Frankencio: Add menu from the editing page doesn't save the changes
parent
53ca7d6a94
commit
eeb96e9b8e
|
|
@ -332,7 +332,12 @@ function menu_ui_form_node_form_alter(&$form, FormStateInterface $form_state) {
|
||||||
'#default_value' => $defaults['weight'],
|
'#default_value' => $defaults['weight'],
|
||||||
'#description' => t('Menu links with lower weights are displayed before links with higher weights.'),
|
'#description' => t('Menu links with lower weights are displayed before links with higher weights.'),
|
||||||
);
|
);
|
||||||
$form['actions']['submit']['#submit'][] = 'menu_ui_form_node_form_submit';
|
|
||||||
|
foreach (array_keys($form['actions']) as $action) {
|
||||||
|
if (isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
|
||||||
|
$form['actions'][$action]['#submit'][] = 'menu_ui_form_node_form_submit';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,13 @@ use Drupal\menu_link_content\Entity\MenuLinkContent;
|
||||||
*/
|
*/
|
||||||
class MenuNodeTest extends WebTestBase {
|
class MenuNodeTest extends WebTestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An editor user.
|
||||||
|
*
|
||||||
|
* @var \Drupal\user\UserInterface
|
||||||
|
*/
|
||||||
|
protected $editor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modules to enable.
|
* Modules to enable.
|
||||||
*
|
*
|
||||||
|
|
@ -31,14 +38,15 @@ class MenuNodeTest extends WebTestBase {
|
||||||
|
|
||||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
||||||
|
|
||||||
$this->drupalLogin($this->drupalCreateUser(array(
|
$this->editor = $this->drupalCreateUser(array(
|
||||||
'access administration pages',
|
'access administration pages',
|
||||||
'administer content types',
|
'administer content types',
|
||||||
'administer menu',
|
'administer menu',
|
||||||
'create page content',
|
'create page content',
|
||||||
'edit any page content',
|
'edit any page content',
|
||||||
'delete any page content',
|
'delete any page content',
|
||||||
)));
|
));
|
||||||
|
$this->drupalLogin($this->editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -104,6 +112,36 @@ class MenuNodeTest extends WebTestBase {
|
||||||
$this->drupalGet('test-page');
|
$this->drupalGet('test-page');
|
||||||
$this->assertNoLink($node_title);
|
$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'.
|
||||||
|
// These buttons just appear for 'administer nodes' users.
|
||||||
|
$admin_user = $this->drupalCreateUser([
|
||||||
|
'access administration pages',
|
||||||
|
'administer content types',
|
||||||
|
'administer nodes',
|
||||||
|
'administer menu',
|
||||||
|
'create page content',
|
||||||
|
'edit any page content',
|
||||||
|
]);
|
||||||
|
$this->drupalLogin($admin_user);
|
||||||
|
foreach ([t('Save and unpublish') => FALSE, t('Save and keep unpublished') => FALSE, t('Save and publish') => TRUE, t('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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log back in as normal user.
|
||||||
|
$this->drupalLogin($this->editor);
|
||||||
// Edit the node and create a menu link.
|
// Edit the node and create a menu link.
|
||||||
$edit = array(
|
$edit = array(
|
||||||
'menu[enabled]' => 1,
|
'menu[enabled]' => 1,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue