Skip to content

Commit 68a676a

Browse files
authored
Merge pull request #44 from maximehuran/feature/url-provider
feat(menu): add menu provider class
2 parents 29c27e5 + c3d367b commit 68a676a

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ parameters:
1010
# Test dependencies
1111
- 'tests/Application/**/*'
1212

13+
# Menu Provider
14+
- 'src/Menu/HomepageUrlProvider.php'
15+
1316
ignoreErrors:
1417
- identifier: missingType.generics
1518
- identifier: missingType.iterableValue

src/Menu/HomepageUrlProvider.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Monsieur Biz' Homepage plugin for Sylius.
5+
*
6+
* (c) Monsieur Biz <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace App\Menu;
15+
16+
use MonsieurBiz\SyliusMenuPlugin\Provider\AbstractUrlProvider;
17+
use Symfony\Component\Routing\RouterInterface;
18+
use Symfony\Contracts\Translation\TranslatorInterface;
19+
20+
class HomepageUrlProvider extends AbstractUrlProvider
21+
{
22+
public const PROVIDER_CODE = 'homepage';
23+
24+
protected string $code = self::PROVIDER_CODE;
25+
26+
protected string $icon = 'home';
27+
28+
protected int $priority = 1000;
29+
30+
public function __construct(
31+
RouterInterface $router,
32+
private TranslatorInterface $translator
33+
) {
34+
parent::__construct($router);
35+
}
36+
37+
/**
38+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
39+
*/
40+
protected function getResults(string $locale, string $search = ''): iterable
41+
{
42+
return [
43+
(object) [
44+
'title' => $this->translator->trans('monsieurbiz_homepage.ui.homepage', [], 'messages', $locale),
45+
],
46+
];
47+
}
48+
49+
protected function addItemFromResult(object $result, string $locale): void
50+
{
51+
$this->addItem(
52+
(string) $result->title,
53+
$this->router->generate('monsieurbiz_sylius_homepage_homepage', ['_locale' => $locale])
54+
);
55+
}
56+
}

src/Resources/translations/messages.en.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ monsieurbiz_homepage:
22
ui:
33
cms_content: 'CMS contents'
44
homepages: 'Homepages'
5+
homepage: 'Homepage'
56
homepages_subheader: 'Manage your homepages'
67
new_homepage: 'New homepage'
78
edit_homepage: 'Edit homepage'
@@ -23,3 +24,6 @@ sylius_plus:
2324
rbac:
2425
parent:
2526
homepages: 'Homepages'
27+
monsieurbiz_menu:
28+
provider:
29+
homepage: 'Homepage'

src/Resources/translations/messages.fr.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ monsieurbiz_homepage:
22
ui:
33
cms_content: 'Contenus CMS'
44
homepages: 'Pages d''accueil'
5+
homepage: 'Page d''accueil'
56
homepages_subheader: 'Gérez vos pages d''accueil'
67
new_homepage: 'Nouvelle page d''accueil'
78
edit_homepage: 'Édition d''une page d''accueil'
@@ -23,3 +24,6 @@ sylius_plus:
2324
rbac:
2425
parent:
2526
homepages: 'Homepages'
27+
monsieurbiz_menu:
28+
provider:
29+
homepage: 'Page d''accueil'

src/Resources/translations/messages.nl.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ monsieurbiz_homepage:
22
ui:
33
cms_content: 'Inhoud van CMS'
44
homepages: 'Homepagina''s'
5+
homepage: 'Homepagina'
56
homepages_subheader: 'Beheer je homepagina''s'
67
new_homepage: 'Nieuwe homepagina'
78
edit_homepage: 'Homepagina bewerken'
@@ -23,3 +24,6 @@ sylius_plus:
2324
rbac:
2425
parent:
2526
homepages: 'Homepagina''s'
27+
monsieurbiz_menu:
28+
provider:
29+
homepage: 'Homepagina'

0 commit comments

Comments
 (0)