Commit b2e94794 authored by catch's avatar catch

Issue #2781673 by Bambell, Berdir: MenuLinkContent menu links can not be set...

Issue #2781673 by Bambell, Berdir: MenuLinkContent menu links can not be set to no parent once they had one
parent 4beaddb7
......@@ -117,7 +117,9 @@ public function isExpanded() {
* {@inheritdoc}
*/
public function getParentId() {
return $this->get('parent')->value;
// Cast the parent ID to a string, only an empty string means no parent,
// NULL keeps the existing parent.
return (string) $this->get('parent')->value;
}
/**
......
......@@ -188,6 +188,20 @@ function testMenuLinkReparenting($module = 'menu_test') {
);
$this->assertMenuLinkParents($links, $expected_hierarchy);
// Try changing the parent at the entity level.
$definition = $this->menuLinkManager->getDefinition($links['child-1-2']);
$entity = MenuLinkContent::load($definition['metadata']['entity_id']);
$entity->parent->value = '';
$entity->save();
$expected_hierarchy = array(
'parent' => '',
'child-1-1' => 'parent',
'child-1-2' => '',
'child-2' => 'parent',
);
$this->assertMenuLinkParents($links, $expected_hierarchy);
// @todo Figure out what makes sense to test in terms of automatic
// re-parenting. https://www.drupal.org/node/2309531
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment