Commit 04685e9f authored by Tino Goratsch's avatar Tino Goratsch

rework the breadcrumb, so that structure from the menus is taking precedence

parent ada178ec
......@@ -75,27 +75,15 @@ class Steps extends Core\Breadcrumb\Steps
}
if (!empty($this->stepsFromDb)) {
$dbStepsCount = count($this->stepsFromDb);
$stepsCount = count($this->steps);
$lastDbStepUri = $this->stepsFromDb[$dbStepsCount - 1]['uri'];
$sliceIndex = $this->findMatchingUriIndexInSteps();
if ($stepsCount === 1 && empty($this->steps[0]['uri'])) {
$this->copyTitleFromFirstStepToLastDbStep();
$this->steps[0]['uri'] = $lastDbStepUri;
}
if ($dbStepsCount > 1 && $dbStepsCount >= $stepsCount) {
$this->breadcrumbCache = $this->stepsFromDb;
} elseif ($lastDbStepUri === $this->steps[0]['uri']) {
$this->copyTitleFromFirstStepToLastDbStep();
$this->breadcrumbCache = array_merge($this->stepsFromDb, array_slice($this->steps, 1));
}
$this->breadcrumbCache = array_merge($this->stepsFromDb, array_slice($this->steps, $sliceIndex));
}
}
/**
* Initializes and pre populates the breadcrumb
* @throws \Doctrine\DBAL\DBALException
*/
private function prePopulate()
{
......@@ -158,8 +146,22 @@ class Steps extends Core\Breadcrumb\Steps
return $this;
}
private function copyTitleFromFirstStepToLastDbStep()
/**
* @return int
*/
private function findMatchingUriIndexInSteps(): int
{
$this->stepsFromDb[count($this->stepsFromDb) - 1]['title'] = $this->steps[0]['title'];
$steps = array_reverse($this->steps);
$lastDbStep = end($this->stepsFromDb);
$offset = 0;
foreach ($steps as $index => $step) {
if ($step['uri'] === $lastDbStep['uri']) {
$offset = $index;
break;
}
}
return count($steps) - $offset;
}
}
......@@ -69,7 +69,7 @@ class StepsTest extends \ACP3\Core\Test\Breadcrumb\StepsTest
$expected = [
[
'title' => '{NEWS_NEWS}',
'title' => 'News',
'uri' => '/news/',
'last' => true
]
......@@ -108,7 +108,7 @@ class StepsTest extends \ACP3\Core\Test\Breadcrumb\StepsTest
'uri' => '/news/',
],
[
'title' => '{NEWSLETTER_NEWSLETTER}',
'title' => 'Newsletter',
'uri' => '/newsletter/',
'last' => true
],
......@@ -147,7 +147,7 @@ class StepsTest extends \ACP3\Core\Test\Breadcrumb\StepsTest
'uri' => '/news/',
],
[
'title' => '{NEWSLETTER_NEWSLETTER}',
'title' => 'Newsletter',
'uri' => '/newsletter/',
],
[
......@@ -201,7 +201,7 @@ class StepsTest extends \ACP3\Core\Test\Breadcrumb\StepsTest
$this->assertEquals($expected, $this->steps->getBreadcrumb());
}
public function testGetBreadcrumbLastStepTitleShouldTakePrecedence()
public function testGetBreadcrumbLastDbStepTitleShouldTakePrecedence()
{
$this->setUpMenuItemRepositoryExpectations([
[
......@@ -225,7 +225,7 @@ class StepsTest extends \ACP3\Core\Test\Breadcrumb\StepsTest
$expected = [
[
'title' => 'Lorem Ipsum Dolor',
'title' => 'FooBar',
'uri' => '/articles/index/details/id_1/',
'last' => true
],
......@@ -233,7 +233,7 @@ class StepsTest extends \ACP3\Core\Test\Breadcrumb\StepsTest
$this->assertEquals($expected, $this->steps->getBreadcrumb());
}
public function testGetBreadcrumbLastStepTitleShouldTakePrecedenceWithEmptyUri()
public function testGetBreadcrumbLastDbStepTitleShouldTakePrecedenceWithEmptyUri()
{
$this->setUpMenuItemRepositoryExpectations([
[
......@@ -257,7 +257,7 @@ class StepsTest extends \ACP3\Core\Test\Breadcrumb\StepsTest
$expected = [
[
'title' => 'Lorem Ipsum Dolor',
'title' => 'FooBar',
'uri' => '/articles/index/details/id_1/',
'last' => true
],
......
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