Skip to content

Commit

Permalink
Remove BaseBreadcrumbMenuBlockService::getRootMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Nov 1, 2021
1 parent 9f3287a commit 9fadee7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
24 changes: 24 additions & 0 deletions UPGRADE-3.0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
UPGRADE FROM 2.X to 3.0
=======================

## Refactored `BaseBreadcrumbMenuBlockService`

The class was slightly refactored, so some extension points became final.

The `getRootMenu` method was removed and the logic was moved to the `getMenu` method. You need to call the parent method if you rely on the old logic:

Before:
```php
protected function getMenu(BlockContextInterface $blockContext) {
// come custom logic
}
```
After:
```php
protected function getMenu(BlockContextInterface $blockContext): {
parent::getMenu($blockContext);

// come custom logic

}
```



## SeoPage

If you have implemented a custom seo page, you must adapt the signature of the following new methods to match the one in `SeoPageInterface` again:
Expand Down
26 changes: 9 additions & 17 deletions src/Block/Breadcrumb/BaseBreadcrumbMenuBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,33 +75,18 @@ public function configureSettings(OptionsResolver $resolver): void
'menu_class' => 'list-group',
'children_class' => 'list-group-item',
'menu_template' => '@SonataSeo/Block/breadcrumb.html.twig',
'include_homepage_link' => true,
'include_homepage_link' => \true,
'context' => null,
]);
}

protected function getMenu(BlockContextInterface $blockContext): ItemInterface
{
return $this->getRootMenu($blockContext);
}

final protected function getFactory(): FactoryInterface
{
return $this->factory;
}

abstract protected function getContext(): string;

final protected function getRootMenu(BlockContextInterface $blockContext): ItemInterface
{
$settings = $blockContext->getSettings();
/*
* @todo : Use the router to get the homepage URI
*/

$menu = $this->factory->createItem('breadcrumb');
$menu->setChildrenAttribute('class', 'breadcrumb');
$menu->setCurrent(true);
$menu->setCurrent(\true);
$menu->setUri($settings['current_uri']);

if ($settings['include_homepage_link']) {
Expand All @@ -111,6 +96,13 @@ final protected function getRootMenu(BlockContextInterface $blockContext): ItemI
return $menu;
}

final protected function getFactory(): FactoryInterface
{
return $this->factory;
}

abstract protected function getContext(): string;

/**
* Replaces setting keys with knp menu item options keys.
*
Expand Down
10 changes: 0 additions & 10 deletions src/Block/Breadcrumb/HomepageBreadcrumbBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

namespace Sonata\SeoBundle\Block\Breadcrumb;

use Knp\Menu\ItemInterface;
use Sonata\BlockBundle\Block\BlockContextInterface;

/**
* BlockService for homepage breadcrumb.
*
Expand All @@ -27,11 +24,4 @@ protected function getContext(): string
{
return 'homepage';
}

protected function getMenu(BlockContextInterface $blockContext): ItemInterface
{
$menu = $this->getRootMenu($blockContext);

return $menu;
}
}
8 changes: 1 addition & 7 deletions tests/Block/Breadcrumb/BreadcrumbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Sonata\BlockBundle\Block\BlockContext;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Model\Block;
use Sonata\BlockBundle\Test\BlockServiceTestCase;
use Sonata\SeoBundle\Block\Breadcrumb\BaseBreadcrumbMenuBlockService;
Expand All @@ -29,11 +28,6 @@ protected function getContext(): string
{
return 'test';
}

protected function getMenu(BlockContextInterface $blockContext): ItemInterface
{
return $this->getRootMenu($blockContext);
}
}

/**
Expand Down Expand Up @@ -93,7 +87,7 @@ public function testDefaultSettings(): void
'menu_class' => 'list-group',
'children_class' => 'list-group-item',
'menu_template' => '@SonataSeo/Block/breadcrumb.html.twig',
'include_homepage_link' => true,
'include_homepage_link' => \true,
'context' => null,
], $blockContext);
}
Expand Down

0 comments on commit 9fadee7

Please sign in to comment.