Navigation: Merge other navigations more sophisticated

refs #5600
This commit is contained in:
Johannes Meyer 2015-09-03 09:57:52 +02:00
parent 537db6000e
commit e6a6ae996a
1 changed files with 19 additions and 1 deletions

View File

@ -316,7 +316,25 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate
public function merge(Navigation $navigation)
{
foreach ($navigation as $item) {
$this->addItem($item);
/** @var $item NavigationItem */
if (($existingItem = $this->getItem($item->getName())) !== null) {
if ($existingItem->conflictsWith($item)) {
$name = $item->getName();
do {
if (preg_match('~_(\d+)$~', $name, $matches)) {
$name = preg_replace('~_\d+$~', $matches[1] + 1, $name);
} else {
$name .= '_2';
}
} while ($this->getItem($name) !== null);
$this->addItem($item->setName($name));
} else {
$existingItem->merge($item);
}
} else {
$this->addItem($item);
}
}
return $this;