-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from maximehuran/feature/cms-menu-provider
Add compatibility with Menu URL provider
- Loading branch information
Showing
5 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SYLIUS_FIXTURES_HOSTNAME=${SYMFONY_DEFAULT_ROUTE_HOST:-localhost} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,6 @@ parameters: | |
|
||
# Test dependencies | ||
- 'tests/Application/**/*' | ||
|
||
# Menu Provider | ||
- 'src/Menu/PageUrlProvider.php' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Cms Page plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusCmsPagePlugin\Menu; | ||
|
||
use MonsieurBiz\SyliusCmsPagePlugin\Entity\PageInterface; | ||
use MonsieurBiz\SyliusCmsPagePlugin\Repository\PageRepositoryInterface; | ||
use MonsieurBiz\SyliusMenuPlugin\Provider\AbstractUrlProvider; | ||
use Symfony\Component\Routing\RouterInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
class PageUrlProvider extends AbstractUrlProvider | ||
{ | ||
public const PROVIDER_CODE = 'page'; | ||
|
||
protected string $code = self::PROVIDER_CODE; | ||
|
||
protected string $icon = 'file alternate'; | ||
|
||
protected int $priority = 40; | ||
|
||
public function __construct( | ||
RouterInterface $router, | ||
private PageRepositoryInterface $pageRepository, | ||
) { | ||
parent::__construct($router); | ||
} | ||
|
||
protected function getResults(string $locale, string $search = ''): iterable | ||
{ | ||
$queryBuilder = $this->pageRepository->createListQueryBuilder($locale) | ||
->andWhere('o.enabled = :enabled') | ||
->setParameter('enabled', true) | ||
; | ||
|
||
if (!empty($search)) { | ||
$queryBuilder | ||
->andWhere('translation.title LIKE :search OR translation.slug LIKE :search') | ||
->setParameter('search', '%' . $search . '%') | ||
; | ||
} | ||
|
||
$queryBuilder->setMaxResults($this->getMaxResults()); | ||
|
||
/** @phpstan-ignore-next-line */ | ||
return $queryBuilder->getQuery()->getResult(); | ||
} | ||
|
||
protected function addItemFromResult(object $result, string $locale): void | ||
{ | ||
Assert::isInstanceOf($result, PageInterface::class); | ||
/** @var PageInterface $result */ | ||
$result->setCurrentLocale($locale); | ||
$this->addItem( | ||
(string) $result->getTitle(), | ||
$this->router->generate('monsieurbiz_cms_page_show', ['slug' => $result->getSlug(), '_locale' => $locale]) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters