Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IndexBundle] split conditions into pre_conditions and user_conditions #1055

Merged
merged 1 commit into from
Sep 11, 2019
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
15 changes: 12 additions & 3 deletions src/CoreShop/Bundle/IndexBundle/Controller/FilterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public function getConfigAction()
return $this->viewHandler->handle(
[
'success' => true,
'conditions' => array_keys($this->getConditionTypes()),
'pre_conditions' => array_keys($this->getPreConditionTypes()),
'user_conditions' => array_keys($this->getUserConditionTypes()),
]
);
}
Expand Down Expand Up @@ -89,8 +90,16 @@ public function getValuesForFilterFieldAction(Request $request)
/**
* @return array
*/
protected function getConditionTypes()
protected function getPreConditionTypes()
{
return $this->getParameter('coreshop.filter.condition_types');
return $this->getParameter('coreshop.filter.pre_condition_types');
}

/**
* @return array
*/
protected function getUserConditionTypes()
{
return $this->getParameter('coreshop.filter.user_condition_types');
}
}
4 changes: 4 additions & 0 deletions src/CoreShop/Bundle/IndexBundle/CoreShopIndexBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterExtensionsPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterColumnTypePass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterFilterConditionTypesPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterFilterPreConditionTypesPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterFilterUserConditionTypesPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterGetterPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterIndexWorkerPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterInterpreterPass;
Expand Down Expand Up @@ -65,6 +67,8 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new RegisterExtensionsPass());
$container->addCompilerPass(new RegisterConditionRendererTypesPass());
$container->addCompilerPass(new RegisterOrderRendererTypesPass());
$container->addCompilerPass(new RegisterFilterPreConditionTypesPass());
$container->addCompilerPass(new RegisterFilterUserConditionTypesPass());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@

namespace CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterRegistryTypePass;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class RegisterFilterConditionTypesPass extends RegisterRegistryTypePass
class RegisterFilterConditionTypesPass implements CompilerPassInterface
{
public const INDEX_FILTER_CONDITION_TAG = 'coreshop.filter.condition_type';

public function __construct()
public function process(ContainerBuilder $container)
{
parent::__construct(
'coreshop.registry.filter.condition_types',
'coreshop.form_registry.filter.condition_types',
'coreshop.filter.condition_types',
self::INDEX_FILTER_CONDITION_TAG
);
foreach ($container->findTaggedServiceIds(self::INDEX_FILTER_CONDITION_TAG) as $id => $attributes) {
$definition = $container->findDefinition($id);

$definition->addTag('coreshop.filter.user_condition_type', $attributes[0]);
$definition->addTag('coreshop.filter.pre_condition_type', $attributes[0]);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterRegistryTypePass;

class RegisterFilterPreConditionTypesPass extends RegisterRegistryTypePass
{
public const INDEX_FILTER_PRE_CONDITION_TAG = 'coreshop.filter.pre_condition_type';

public function __construct()
{
parent::__construct(
'coreshop.registry.filter.pre_condition_types',
'coreshop.form_registry.filter.pre_condition_types',
'coreshop.filter.pre_condition_types',
self::INDEX_FILTER_PRE_CONDITION_TAG
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterRegistryTypePass;

class RegisterFilterUserConditionTypesPass extends RegisterRegistryTypePass
{
public const INDEX_FILTER_USER_CONDITION_TAG = 'coreshop.filter.user_condition_type';

public function __construct()
{
parent::__construct(
'coreshop.registry.filter.user_condition_types',
'coreshop.form_registry.filter.user_condition_types',
'coreshop.filter.user_condition_types',
self::INDEX_FILTER_USER_CONDITION_TAG
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterConditionRendererTypesPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterExtensionsPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterFilterConditionTypesPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterFilterPreConditionTypesPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterFilterUserConditionTypesPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterGetterPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterIndexWorkerPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterInterpreterPass;
Expand All @@ -23,6 +25,8 @@
use CoreShop\Component\Index\Condition\DynamicRendererInterface;
use CoreShop\Component\Index\Extension\IndexExtensionInterface;
use CoreShop\Component\Index\Filter\FilterConditionProcessorInterface;
use CoreShop\Component\Index\Filter\FilterPreConditionProcessorInterface;
use CoreShop\Component\Index\Filter\FilterUserConditionProcessorInterface;
use CoreShop\Component\Index\Getter\GetterInterface;
use CoreShop\Component\Index\Interpreter\InterpreterInterface;
use CoreShop\Component\Index\Order\DynamicOrderRendererInterface;
Expand Down Expand Up @@ -84,6 +88,16 @@ public function load(array $config, ContainerBuilder $container)
->addTag(RegisterFilterConditionTypesPass::INDEX_FILTER_CONDITION_TAG)
;

$container
->registerForAutoconfiguration(FilterPreConditionProcessorInterface::class)
->addTag(RegisterFilterPreConditionTypesPass::INDEX_FILTER_PRE_CONDITION_TAG)
;

$container
->registerForAutoconfiguration(FilterUserConditionProcessorInterface::class)
->addTag(RegisterFilterUserConditionTypesPass::INDEX_FILTER_USER_CONDITION_TAG)
;

$container
->registerForAutoconfiguration(GetterInterface::class)
->addTag(RegisterGetterPass::INDEX_GETTER_TAG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,21 @@

namespace CoreShop\Bundle\IndexBundle\Form\Type\Filter;

use CoreShop\Bundle\IndexBundle\Form\Type\FilterConditionCollectionType;
use CoreShop\Component\Resource\Repository\RepositoryInterface;
use CoreShop\Bundle\IndexBundle\Form\Type\FilterPreConditionCollectionType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

final class FilterConditionNestedType extends AbstractType
final class FilterPreConditionNestedType extends AbstractType
{
/**
* @var RepositoryInterface
*/
private $repository;

/**
* @param RepositoryInterface $repository
*/
public function __construct(RepositoryInterface $repository)
{
$this->repository = $repository;
}

/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('conditions', FilterConditionCollectionType::class);
->add('conditions', FilterPreConditionCollectionType::class);

$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$data = $event->getData();
Expand All @@ -58,6 +44,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
*/
public function getBlockPrefix()
{
return 'coreshop_filter_condition_type_nested';
return 'coreshop_filter_pre_condition_type_nested';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Bundle\IndexBundle\Form\Type\Filter;

use CoreShop\Bundle\IndexBundle\Form\Type\FilterUserConditionCollectionType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

final class FilterUserConditionNestedType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('conditions', FilterUserConditionCollectionType::class);

$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$data = $event->getData();

if (is_array($data)) {
$data['conditions'] = [];

$event->setData($data);
}
});
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'coreshop_filter_user_condition_type_nested';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class FilterConditionType extends AbstractResourceType
class FilterConditionType extends AbstractResourceType
{
/**
* @var FormTypeRegistryInterface
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Bundle\IndexBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class FilterPreConditionChoiceType extends AbstractType
{
/**
* @var array
*/
private $types;

/**
* @param array $types
*/
public function __construct(array $types)
{
$this->types = $types;
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'choices' => array_flip($this->types),
]);
}

/**
* {@inheritdoc}
*/
public function getParent()
{
return ChoiceType::class;
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'coreshop_filter_pre_condition_choice';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
use CoreShop\Bundle\IndexBundle\Form\Type\Core\AbstractConfigurationCollectionType;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class FilterConditionCollectionType extends AbstractConfigurationCollectionType
final class FilterPreConditionCollectionType extends AbstractConfigurationCollectionType
{
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);

$resolver->setDefault('entry_type', FilterConditionType::class);
$resolver->setDefault('entry_type', FilterPreConditionType::class);
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'coreshop_filter_condition_collection';
return 'coreshop_filter_pre_condition_collection';
}
}
Loading