-
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.
- Loading branch information
Bertrand Dunogier
committed
Feb 18, 2020
1 parent
e30726e
commit e28f815
Showing
10 changed files
with
594 additions
and
1 deletion.
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
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
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
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,81 @@ | ||
<?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\NamedQuery; | ||
|
||
use eZ\Publish\API\Repository\ContentTypeService; | ||
use eZ\Publish\Core\QueryType\QueryTypeRegistry; | ||
use EzSystems\EzPlatformQueryFieldType\eZ\FieldType\Mapper\ParametersTransformer; | ||
use EzSystems\RepositoryForms\Data\FieldDefinitionData; | ||
use EzSystems\RepositoryForms\FieldType\FieldDefinitionFormMapperInterface; | ||
use Symfony\Component\Form\Extension\Core\Type; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
final class Mapper implements FieldDefinitionFormMapperInterface | ||
{ | ||
/** @var ContentTypeService */ | ||
private $contentTypeService; | ||
/** | ||
* @var string | ||
*/ | ||
private $queryType; | ||
/** | ||
* @var \eZ\Publish\Core\QueryType\QueryTypeRegistry | ||
*/ | ||
private $queryTypeRegistry; | ||
|
||
public function __construct(ContentTypeService $contentTypeService, QueryTypeRegistry $queryTypeRegistry, string $queryType) | ||
{ | ||
$this->contentTypeService = $contentTypeService; | ||
$this->queryType = $queryType; | ||
$this->queryTypeRegistry = $queryTypeRegistry; | ||
} | ||
|
||
public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data) | ||
{ | ||
$parametersForm = $fieldDefinitionForm->getConfig()->getFormFactory()->createBuilder() | ||
->create( | ||
'Parameters', | ||
Type\TextareaType::class, | ||
[ | ||
'label' => 'Parameters', | ||
'property_path' => 'fieldSettings[Parameters]', | ||
] | ||
) | ||
->addModelTransformer(new ParametersTransformer()) | ||
->setAutoInitialize(false) | ||
->getForm(); | ||
|
||
$fieldDefinitionForm | ||
->add('ReturnedType', Type\ChoiceType::class, | ||
[ | ||
'label' => 'Returned type', | ||
'property_path' => 'fieldSettings[ReturnedType]', | ||
'choices' => $this->getContentTypes(), | ||
'required' => true, | ||
] | ||
) | ||
->add($parametersForm); | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver | ||
->setDefaults([ | ||
'translation_domain' => 'ezrepoforms_content_type', | ||
]); | ||
} | ||
|
||
private function getContentTypes() | ||
{ | ||
foreach ($this->contentTypeService->loadContentTypeGroups() as $contentTypeGroup) { | ||
foreach ($this->contentTypeService->loadContentTypes($contentTypeGroup) as $contentType) { | ||
yield $contentType->getName() => $contentType->identifier; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.