Issue #2396761 by chx: menu tree storage override requires too much copy-paste
parent
9a2b86b27d
commit
1777332e85
|
@ -358,34 +358,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
|
|||
foreach ($this->serializedFields() as $name) {
|
||||
$fields[$name] = serialize($fields[$name]);
|
||||
}
|
||||
|
||||
// Directly fill parents for top-level links.
|
||||
if (empty($link['parent'])) {
|
||||
$fields['p1'] = $link['mlid'];
|
||||
for ($i = 2; $i <= $this->maxDepth(); $i++) {
|
||||
$fields["p$i"] = 0;
|
||||
}
|
||||
$fields['depth'] = 1;
|
||||
}
|
||||
// Otherwise, ensure that this link's depth is not beyond the maximum depth
|
||||
// and fill parents based on the parent link.
|
||||
else {
|
||||
// @todo We want to also check $original['has_children'] here, but that
|
||||
// will be 0 even if there are children if those are not enabled.
|
||||
// has_children is really just the rendering hint. So, we either need
|
||||
// to define another column (has_any_children), or do the extra query.
|
||||
// https://www.drupal.org/node/2302149
|
||||
if ($original) {
|
||||
$limit = $this->maxDepth() - $this->doFindChildrenRelativeDepth($original) - 1;
|
||||
}
|
||||
else {
|
||||
$limit = $this->maxDepth() - 1;
|
||||
}
|
||||
if ($parent['depth'] > $limit) {
|
||||
throw new PluginException(String::format('The link with ID @id or its children exceeded the maximum depth of @depth', array('@id' => $link['id'], '@depth' => $this->maxDepth())));
|
||||
}
|
||||
$this->setParents($fields, $parent);
|
||||
}
|
||||
$this->setParents($fields, $parent, $original);
|
||||
|
||||
// Need to check both parent and menu_name, since parent can be empty in any
|
||||
// menu.
|
||||
|
@ -463,10 +436,37 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
|
|||
*
|
||||
* @param array $fields
|
||||
* The menu link.
|
||||
* @param array $parent
|
||||
* @param array|false $parent
|
||||
* The parent menu link.
|
||||
* @param array $original
|
||||
* The original menu link.
|
||||
*/
|
||||
protected function setParents(array &$fields, array $parent) {
|
||||
protected function setParents(array &$fields, $parent, array $original) {
|
||||
// Directly fill parents for top-level links.
|
||||
if (empty($fields['parent'])) {
|
||||
$fields['p1'] = $fields['mlid'];
|
||||
for ($i = 2; $i <= $this->maxDepth(); $i++) {
|
||||
$fields["p$i"] = 0;
|
||||
}
|
||||
$fields['depth'] = 1;
|
||||
}
|
||||
// Otherwise, ensure that this link's depth is not beyond the maximum depth
|
||||
// and fill parents based on the parent link.
|
||||
else {
|
||||
// @todo We want to also check $original['has_children'] here, but that
|
||||
// will be 0 even if there are children if those are not enabled.
|
||||
// has_children is really just the rendering hint. So, we either need
|
||||
// to define another column (has_any_children), or do the extra query.
|
||||
// https://www.drupal.org/node/2302149
|
||||
if ($original) {
|
||||
$limit = $this->maxDepth() - $this->doFindChildrenRelativeDepth($original) - 1;
|
||||
}
|
||||
else {
|
||||
$limit = $this->maxDepth() - 1;
|
||||
}
|
||||
if ($parent['depth'] > $limit) {
|
||||
throw new PluginException(String::format('The link with ID @id or its children exceeded the maximum depth of @depth', array('@id' => $fields['id'], '@depth' => $this->maxDepth())));
|
||||
}
|
||||
$fields['depth'] = $parent['depth'] + 1;
|
||||
$i = 1;
|
||||
while ($i < $fields['depth']) {
|
||||
|
@ -481,6 +481,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
|
|||
$fields[$p] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-parents a link's children when the link itself is moved.
|
||||
|
|
Loading…
Reference in New Issue