Skip to content

Commit 34de94f

Browse files
authored
Merge pull request #52 from lanfisis/1.x
Add enabled / disabled capability for menu items
2 parents def8982 + 3f1da96 commit 34de94f

File tree

18 files changed

+140
-12
lines changed

18 files changed

+140
-12
lines changed

.github/workflows/recipe.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
working-directory: ./sylius
6363
run: |
6464
composer require --no-install --no-scripts --no-progress sylius/sylius="${{ matrix.sylius }}"
65+
composer require --no-install --no-scripts --no-progress symfony/serializer "<6.4.23" # Temporary fix for Sylius 1.x
6566
6667
- name: Setup some requirements
6768
working-directory: ./sylius

.github/workflows/tests.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
php: ['8.1', '8.2', '8.3']
18+
node: ['20']
1819

1920
env:
2021
SYMFONY_ARGS: --no-tls
@@ -25,7 +26,7 @@ jobs:
2526
- uses: actions/checkout@v2
2627
- uses: actions/setup-node@v2
2728
with:
28-
node-version: '14'
29+
node-version: '20'
2930
- name: Setup PHP
3031
uses: shivammathur/setup-php@v2
3132
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
/.phpunit.result.cache
1717
/node_modules
1818
/yarn.lock
19+
/.php-cs-fixer.cache

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ setup_application:
7272
(cd ${APP_DIR} && ${COMPOSER} config --no-plugins allow-plugins true)
7373
(cd ${APP_DIR} && ${COMPOSER} config --no-plugins --json extra.symfony.endpoint '["https://api.github.com/repos/monsieurbiz/symfony-recipes/contents/index.json?ref=flex/master","flex://defaults"]')
7474
(cd ${APP_DIR} && ${COMPOSER} require --no-install --no-scripts --no-progress sylius/sylius="~${SYLIUS_VERSION}") # Make sure to install the required version of sylius because the sylius-standard has a soft constraint
75+
# Temporary fix for Sylius 1.x
76+
(cd ${APP_DIR} && ${COMPOSER} require --no-install --no-scripts --no-progress symfony/serializer "<6.4.23")
77+
# End Temporary fix for Sylius 1.x
7578
$(MAKE) ${APP_DIR}/.php-version
7679
$(MAKE) ${APP_DIR}/php.ini
7780
(cd ${APP_DIR} && ${COMPOSER} install --no-interaction)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Monsieur Biz' Menu plugin for Sylius.
5+
*
6+
* (c) Monsieur Biz <sylius@monsieurbiz.com>
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\Context\Channel\RequestBased;
15+
16+
use Sylius\Component\Channel\Context\RequestBased\RequestResolverInterface;
17+
use Sylius\Component\Channel\Model\ChannelInterface;
18+
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
19+
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
20+
use Symfony\Component\HttpFoundation\Request;
21+
22+
#[AutoconfigureTag('sylius.context.channel.request_based.resolver')]
23+
final class HostnameAndPortBasedRequestResolver implements RequestResolverInterface
24+
{
25+
public function __construct(private ChannelRepositoryInterface $channelRepository)
26+
{
27+
}
28+
29+
public function findChannel(Request $request): ?ChannelInterface
30+
{
31+
return $this->channelRepository->findOneEnabledByHostname($request->getHost() . ':' . $request->getPort());
32+
}
33+
}

src/Entity/MenuItem.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class MenuItem implements MenuItemInterface
4949

5050
protected bool $nofollow = false;
5151

52+
protected bool $enabled = true;
53+
5254
/**
5355
* MenuItem constructor.
5456
*/
@@ -228,4 +230,20 @@ protected function createTranslation(): MenuItemTranslationInterface
228230
{
229231
return new MenuItemTranslation();
230232
}
233+
234+
/**
235+
* @inheritdoc
236+
*/
237+
public function isEnabled(): bool
238+
{
239+
return $this->enabled;
240+
}
241+
242+
/**
243+
* @inheritdoc
244+
*/
245+
public function setEnabled(bool $enabled): void
246+
{
247+
$this->enabled = $enabled;
248+
}
231249
}

src/Entity/MenuItemInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,8 @@ public function setNofollow(bool $nofollow): void;
6666
public function getLabel(): ?string;
6767

6868
public function getUrl(): ?string;
69+
70+
public function isEnabled(): bool;
71+
72+
public function setEnabled(bool $enabled): void;
6973
}

src/Fixture/Factory/MenuFixtureFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ private function createMenuItem(array $item, int $position, MenuInterface $menu,
8383
$menuItem->setPosition($position);
8484
$menuItem->setMenu($menu);
8585

86+
$menuItem->setEnabled($item['enabled'] ?? true);
8687
$menuItem->setTargetBlank($item['targetBlank'] ?? false);
8788
$menuItem->setNoreferrer($item['noreferrer'] ?? false);
8889
$menuItem->setNoopener($item['noopener'] ?? false);

src/Fixture/MenuFixture.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function configureResourceNode(ArrayNodeDefinition $resourceNode): void
4444
->end()
4545
->end()
4646
->end()
47+
->booleanNode('enabled')->defaultTrue()->end()
4748
->booleanNode('targetBlank')->defaultFalse()->end()
4849
->booleanNode('noreferrer')->defaultFalse()->end()
4950
->booleanNode('noopener')->defaultFalse()->end()

src/Form/Type/MenuItemType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
3939
/** @var MenuItemInterface $item */
4040
Assert::isInstanceOf($item, MenuItemInterface::class);
4141
$event->getForm()
42+
->add('enabled', CheckboxType::class, [
43+
'label' => 'monsieurbiz_menu.ui.enabled',
44+
'required' => false,
45+
])
4246
->add('parent', EntityType::class, [
4347
'class' => $this->dataClass,
4448
'required' => false,

0 commit comments

Comments
 (0)