-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prototyped a more advanced query type parameters UI
- Loading branch information
Bertrand Dunogier
committed
Dec 13, 2019
1 parent
4980d89
commit f2e208d
Showing
6 changed files
with
117 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/eZ/FieldType/Form/EventSubscriber/FieldDefinitionParametersSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\EzPlatformQueryFieldType\eZ\FieldType\Form\EventSubscriber; | ||
|
||
use eZ\Publish\Core\QueryType\QueryTypeRegistry; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\Form\Extension\Core\Type; | ||
use Symfony\Component\Form\FormEvent; | ||
use Symfony\Component\Form\FormEvents; | ||
|
||
class FieldDefinitionParametersSubscriber implements EventSubscriberInterface | ||
{ | ||
/** @var \eZ\Publish\Core\QueryType\QueryTypeRegistry */ | ||
private $queryTypeRegistry; | ||
|
||
public function __construct(QueryTypeRegistry $queryTypeRegistry) | ||
{ | ||
$this->queryTypeRegistry = $queryTypeRegistry; | ||
} | ||
|
||
public static function getSubscribedEvents() | ||
{ | ||
return [FormEvents::PRE_SET_DATA => 'addParametersFormFields']; | ||
} | ||
|
||
public function addParametersFormFields(FormEvent $event) | ||
{ | ||
$data = $event->getData(); | ||
if ($data === null) { | ||
return; | ||
} | ||
|
||
$queryTypeIdentifier = $event->getForm()->getConfig()->getOption('query_type'); | ||
if ($queryTypeIdentifier === null) { | ||
return; | ||
} | ||
|
||
$queryType = $this->queryTypeRegistry->getQueryType($queryTypeIdentifier); | ||
foreach ($queryType->getSupportedParameters() as $parameter) { | ||
$event->getForm()->add( | ||
$parameter, | ||
Type\TextType::class, | ||
[ | ||
'label' => $parameter, | ||
'property_path' => sprintf('[Parameters][%s]', $parameter), | ||
'required' => false, | ||
] | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\EzPlatformQueryFieldType\eZ\FieldType\Form; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class FieldDefinitionParametersType extends AbstractType | ||
{ | ||
/** @var \Symfony\Component\EventDispatcher\EventSubscriberInterface */ | ||
private $parametersSubscriber; | ||
|
||
public function __construct(EventSubscriberInterface $parametersSubscriber) | ||
{ | ||
$this->parametersSubscriber = $parametersSubscriber; | ||
} | ||
|
||
public function getParent() | ||
{ | ||
return Type\FormType::class; | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefault('query_type', null); | ||
} | ||
|
||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder->addEventSubscriber($this->parametersSubscriber); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters