Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ parameters:
identifier: method.nonObject
count: 166
path: src/Bundle/DependencyInjection/Configuration.php
# Symfony Dependency Injection Reflector
- message: '#^Parameter \#2 \$configurator of method Symfony\\Component\\DependencyInjection\\ContainerBuilder\:\:registerAttributeForAutoconfiguration\(\)#'
identifier: argument.type
count: 2
path: src/Bundle/DependencyInjection/SyliusGridExtension.php
# Symfony 8 without Doctrine PHPCR-ODM
- message: '#^Method Sylius\\Bundle\\GridBundle\\Doctrine\\DataSourceInterface\:\:getQueryBuilder\(\) has invalid return type Doctrine\\ODM\\PHPCR\\Query\\Builder\\QueryBuilder\.$#'
identifier: class.notFound
Expand Down
17 changes: 11 additions & 6 deletions src/Bundle/DependencyInjection/SyliusGridExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Sylius\Bundle\GridBundle\Grid\GridInterface;
use Sylius\Bundle\GridBundle\SyliusGridBundle;
use Sylius\Component\Grid\Annotation\AsGridFieldCallableService;
use Sylius\Component\Grid\Attribute\AsField;
use Sylius\Component\Grid\Attribute\AsFilter;
use Sylius\Component\Grid\Data\DataProviderInterface;
use Sylius\Component\Grid\Filtering\ConfigurableFilterInterface;
Expand Down Expand Up @@ -84,12 +85,7 @@ public function load(array $configs, ContainerBuilder $container): void

$container->registerAttributeForAutoconfiguration(
AsFilter::class,
static function (ChildDefinition $definition, AsFilter $attribute, \Reflector $reflector): void {
// Helps to avoid issues with psalm
if (!$reflector instanceof \ReflectionClass) {
return;
}

static function (ChildDefinition $definition, AsFilter $attribute, \ReflectionClass $reflector): void {
$definition->addTag(AsFilter::SERVICE_TAG, [
'type' => $attribute->type ?? $reflector->getName(),
'form_type' => $attribute->formType,
Expand All @@ -98,6 +94,15 @@ static function (ChildDefinition $definition, AsFilter $attribute, \Reflector $r
},
);

$container->registerAttributeForAutoconfiguration(
AsField::class,
static function (ChildDefinition $definition, AsField $attribute, \ReflectionClass $reflector): void {
$definition->addTag(AsField::SERVICE_TAG, [
'type' => $attribute->type ?? $reflector->getName(),
]);
},
);

$container->registerForAutoconfiguration(ConfigurableFilterInterface::class)
->addTag(AsFilter::SERVICE_TAG)
;
Expand Down
32 changes: 32 additions & 0 deletions src/Bundle/Tests/Integration/CustomFiltersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Integration;

use App\Field\FirstCustomField;
use Sylius\Component\Registry\ServiceRegistry;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

final class CustomFiltersTest extends KernelTestCase
{
public function testItRegistersCustomFilters(): void
{
$container = static::getContainer();

/** @var ServiceRegistry $fieldRegistry */
$fieldRegistry = $container->get('sylius.registry.grid_field');

self::assertTrue($fieldRegistry->has(FirstCustomField::class));
self::assertTrue($fieldRegistry->has('custom_two'));
}
}
25 changes: 25 additions & 0 deletions src/Component/Attribute/AsField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Component\Grid\Attribute;

#[\Attribute(\Attribute::TARGET_CLASS)]
final class AsField
{
public const SERVICE_TAG = 'sylius.grid_field';

public function __construct(
public readonly ?string $type = null,
) {
}
}
32 changes: 32 additions & 0 deletions tests/Application/src/Field/FirstCustomField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Field;

use Sylius\Component\Grid\Attribute\AsField;
use Sylius\Component\Grid\Definition\Field;
use Sylius\Component\Grid\FieldTypes\FieldTypeInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

#[AsField]
class FirstCustomField implements FieldTypeInterface
{
public function render(Field $field, $data, array $options): string
{
return '';
}

public function configureOptions(OptionsResolver $resolver): void
{
}
}
32 changes: 32 additions & 0 deletions tests/Application/src/Field/SecondCustomField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Field;

use Sylius\Component\Grid\Attribute\AsField;
use Sylius\Component\Grid\Definition\Field;
use Sylius\Component\Grid\FieldTypes\FieldTypeInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

#[AsField(type: 'custom_two')]
class SecondCustomField implements FieldTypeInterface
{
public function render(Field $field, $data, array $options): string
{
return '';
}

public function configureOptions(OptionsResolver $resolver): void
{
}
}