Skip to content

Commit

Permalink
Add an age verification tab on the product edit page
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Sep 25, 2024
1 parent 5fd56fe commit c3f8224
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusAgeVerificationPlugin\EventSubscriber\Admin;

use Sylius\Bundle\AdminBundle\Event\ProductMenuBuilderEvent;
use Sylius\Bundle\AdminBundle\Menu\ProductFormMenuBuilder;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

final class AddAgeVerificationTabSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array

Check failure on line 13 in src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

MixedReturnTypeCoercion

src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php:13:51: MixedReturnTypeCoercion: The declared return type 'array<string, array{0?: array{0: string, 1?: int}|string, 1?: array{0: string, 1?: int}|int, ...<int<0, max>, array{0: string, 1?: int}>}|string>' for Setono\SyliusAgeVerificationPlugin\EventSubscriber\Admin\AddAgeVerificationTabSubscriber::getSubscribedEvents is more specific than the inferred return type 'non-empty-array<array-key, 'addTab'>' (see https://psalm.dev/197)

Check failure on line 13 in src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

MixedReturnTypeCoercion

src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php:13:51: MixedReturnTypeCoercion: The declared return type 'array<string, array{0?: array{0: string, 1?: int}|string, 1?: array{0: string, 1?: int}|int, ...<int<0, max>, array{0: string, 1?: int}>}|string>' for Setono\SyliusAgeVerificationPlugin\EventSubscriber\Admin\AddAgeVerificationTabSubscriber::getSubscribedEvents is more specific than the inferred return type 'non-empty-array<array-key, 'addTab'>' (see https://psalm.dev/197)
{
return [

Check failure on line 15 in src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

MixedArrayOffset

src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php:15:16: MixedArrayOffset: Cannot create mixed offset – expecting array-key (see https://psalm.dev/031)

Check failure on line 15 in src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

MixedReturnTypeCoercion

src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php:15:16: MixedReturnTypeCoercion: The type 'non-empty-array<array-key, 'addTab'>' is more general than the declared return type 'array<string, array{0?: array{0: string, 1?: int}|string, 1?: array{0: string, 1?: int}|int, ...<int<0, max>, array{0: string, 1?: int}>}|string>' for Setono\SyliusAgeVerificationPlugin\EventSubscriber\Admin\AddAgeVerificationTabSubscriber::getSubscribedEvents (see https://psalm.dev/197)

Check failure on line 15 in src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

MixedArrayOffset

src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php:15:16: MixedArrayOffset: Cannot create mixed offset – expecting array-key (see https://psalm.dev/031)

Check failure on line 15 in src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

MixedReturnTypeCoercion

src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php:15:16: MixedReturnTypeCoercion: The type 'non-empty-array<array-key, 'addTab'>' is more general than the declared return type 'array<string, array{0?: array{0: string, 1?: int}|string, 1?: array{0: string, 1?: int}|int, ...<int<0, max>, array{0: string, 1?: int}>}|string>' for Setono\SyliusAgeVerificationPlugin\EventSubscriber\Admin\AddAgeVerificationTabSubscriber::getSubscribedEvents (see https://psalm.dev/197)
ProductFormMenuBuilder::EVENT_NAME => 'addTab',

Check failure on line 16 in src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

UndefinedClass

src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php:16:13: UndefinedClass: Class, interface or enum named Sylius\Bundle\AdminBundle\Menu\ProductFormMenuBuilder does not exist (see https://psalm.dev/019)

Check failure on line 16 in src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

UndefinedClass

src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php:16:13: UndefinedClass: Class, interface or enum named Sylius\Bundle\AdminBundle\Menu\ProductFormMenuBuilder does not exist (see https://psalm.dev/019)
];
}

public function addTab(ProductMenuBuilderEvent $event): void

Check failure on line 20 in src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

UndefinedClass

src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php:20:28: UndefinedClass: Class, interface or enum named Sylius\Bundle\AdminBundle\Event\ProductMenuBuilderEvent does not exist (see https://psalm.dev/019)

Check failure on line 20 in src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

UndefinedClass

src/EventSubscriber/Admin/AddAgeVerificationTabSubscriber.php:20:28: UndefinedClass: Class, interface or enum named Sylius\Bundle\AdminBundle\Event\ProductMenuBuilderEvent does not exist (see https://psalm.dev/019)
{
$event->getMenu()
->addChild('age_verification')
->setAttribute('template', '@SetonoSyliusAgeVerificationPlugin/admin/product/tab/_age_verification.html.twig')
->setLabel('setono_sylius_age_verification.ui.age_verification')
;
}
}
26 changes: 26 additions & 0 deletions src/Form/Extension/ProductTypeExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusAgeVerificationPlugin\Form\Extension;

use Sylius\Bundle\ProductBundle\Form\Type\ProductType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\FormBuilderInterface;

final class ProductTypeExtension extends AbstractTypeExtension
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('minimumAge', IntegerType::class, [
'label' => 'setono_sylius_age_verification.form.product.minimum_age',
'required' => false,
]);
}

public static function getExtendedTypes(): \Generator
{
yield ProductType::class;
}
}
8 changes: 7 additions & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<!-- Put your services here -->
<service id="Setono\SyliusAgeVerificationPlugin\Form\Extension\ProductTypeExtension">
<tag name="form.type_extension"/>
</service>

<service id="Setono\SyliusAgeVerificationPlugin\EventSubscriber\Admin\AddAgeVerificationTabSubscriber">
<tag name="kernel.event_subscriber"/>
</service>
</services>
</container>
6 changes: 6 additions & 0 deletions src/Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
setono_sylius_age_verification:
form:
product:
minimum_age: Minimum age
ui:
age_verification: Age verification
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="ui tab" data-tab="age_verification">
<h3 class="ui top attached header">{{ 'setono_sylius_age_verification.ui.age_verification'|trans }}</h3>

<div class="ui attached segment">
{{ form_row(form.minimumAge) }}
</div>
</div>

0 comments on commit c3f8224

Please sign in to comment.