From 801d9ef112defb4573249cb0410c7761d40860d9 Mon Sep 17 00:00:00 2001 From: Maciej Kobus Date: Mon, 12 Mar 2018 16:07:12 +0100 Subject: [PATCH] EZP-28861: Allow template and controller dispatching based on matcher configuration for Content Create (#217) --- bundle/Controller/ContentEditController.php | 55 +--- .../Compiler/ViewBuilderRegistryPass.php | 9 +- .../Parser/ContentCreateView.php | 16 ++ .../Configuration/Parser/ContentEdit.php | 3 +- bundle/EzSystemsRepositoryFormsBundle.php | 2 + .../config/ezpublish_default_settings.yml | 1 + bundle/Resources/config/routing.yml | 1 + bundle/Resources/config/services.yml | 3 - bundle/Resources/config/views.yml | 34 ++- .../View/Builder/ContentCreateViewBuilder.php | 236 ++++++++++++++++++ lib/Content/View/ContentCreateView.php | 85 ++++++- lib/Content/View/ContentTypeValueView.php | 21 ++ .../View/Filter/ContentCreateViewFilter.php | 122 +++++++++ .../Provider/ContentCreateView/Configured.php | 67 +++++ .../{ => ContentEditView}/Configured.php | 2 +- lib/EventListener/UserEditListener.php | 2 + 16 files changed, 600 insertions(+), 59 deletions(-) create mode 100644 bundle/DependencyInjection/Configuration/Parser/ContentCreateView.php create mode 100644 lib/Content/View/Builder/ContentCreateViewBuilder.php create mode 100644 lib/Content/View/ContentTypeValueView.php create mode 100644 lib/Content/View/Filter/ContentCreateViewFilter.php create mode 100644 lib/Content/View/Provider/ContentCreateView/Configured.php rename lib/Content/View/Provider/{ => ContentEditView}/Configured.php (96%) diff --git a/bundle/Controller/ContentEditController.php b/bundle/Controller/ContentEditController.php index 323848f32..f80ba4264 100644 --- a/bundle/Controller/ContentEditController.php +++ b/bundle/Controller/ContentEditController.php @@ -10,16 +10,12 @@ use eZ\Bundle\EzPublishCoreBundle\Controller; use eZ\Publish\API\Repository\ContentService; use eZ\Publish\API\Repository\ContentTypeService; -use eZ\Publish\API\Repository\LanguageService; -use eZ\Publish\API\Repository\LocationService; use EzSystems\RepositoryForms\Content\View\ContentCreateDraftView; use EzSystems\RepositoryForms\Content\View\ContentCreateView; use EzSystems\RepositoryForms\Content\View\ContentEditView; use EzSystems\RepositoryForms\Data\Content\CreateContentDraftData; -use EzSystems\RepositoryForms\Data\Mapper\ContentCreateMapper; use EzSystems\RepositoryForms\Form\ActionDispatcher\ActionDispatcherInterface; use EzSystems\RepositoryForms\Form\Type\Content\ContentDraftCreateType; -use EzSystems\RepositoryForms\Form\Type\Content\ContentEditType; use Symfony\Component\HttpFoundation\Request; class ContentEditController extends Controller @@ -30,72 +26,29 @@ class ContentEditController extends Controller /** @var ContentService */ private $contentService; - /** @var LocationService */ - private $locationService; - - /** @var LanguageService */ - private $languageService; - /** @var ActionDispatcherInterface */ private $contentActionDispatcher; public function __construct( ContentTypeService $contentTypeService, ContentService $contentService, - LocationService $locationService, - LanguageService $languageService, ActionDispatcherInterface $contentActionDispatcher ) { $this->contentTypeService = $contentTypeService; - $this->locationService = $locationService; - $this->languageService = $languageService; - $this->contentActionDispatcher = $contentActionDispatcher; $this->contentService = $contentService; + $this->contentActionDispatcher = $contentActionDispatcher; } /** * Displays and processes a content creation form. Showing the form does not create a draft in the repository. * - * @param int $contentTypeIdentifier ContentType id to create - * @param string $language Language code to create the content in (eng-GB, ger-DE, ...)) - * @param int $parentLocationId Location the content should be a child of - * @param \Symfony\Component\HttpFoundation\Request $request + * @param \EzSystems\RepositoryForms\Content\View\ContentCreateView $view * * @return \EzSystems\RepositoryForms\Content\View\ContentCreateView|\Symfony\Component\HttpFoundation\Response - * - * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType - * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException */ - public function createWithoutDraftAction($contentTypeIdentifier, $language, $parentLocationId, Request $request) + public function createWithoutDraftAction(ContentCreateView $view) { - $language = $this->languageService->loadLanguage($language); - $parentLocation = $this->locationService->loadLocation($parentLocationId); - $contentType = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); - $data = (new ContentCreateMapper())->mapToFormData($contentType, [ - 'mainLanguageCode' => $language->languageCode, - 'parentLocation' => $this->locationService->newLocationCreateStruct($parentLocationId), - ]); - $form = $this->createForm(ContentEditType::class, $data, [ - 'languageCode' => $language->languageCode, - 'mainLanguageCode' => $language->languageCode, - 'drafts_enabled' => true, - ]); - $form->handleRequest($request); - - if ($form->isValid() && null !== $form->getClickedButton()) { - $this->contentActionDispatcher->dispatchFormAction($form, $data, $form->getClickedButton()->getName()); - if ($response = $this->contentActionDispatcher->getResponse()) { - return $response; - } - } - - return new ContentCreateView(null, [ - 'form' => $form->createView(), - 'language' => $language, - 'contentType' => $contentType, - 'parentLocation' => $parentLocation, - ]); + return $view; } /** diff --git a/bundle/DependencyInjection/Compiler/ViewBuilderRegistryPass.php b/bundle/DependencyInjection/Compiler/ViewBuilderRegistryPass.php index b0ef50a41..a31cb2e27 100644 --- a/bundle/DependencyInjection/Compiler/ViewBuilderRegistryPass.php +++ b/bundle/DependencyInjection/Compiler/ViewBuilderRegistryPass.php @@ -7,6 +7,7 @@ */ namespace EzSystems\RepositoryFormsBundle\DependencyInjection\Compiler; +use EzSystems\RepositoryForms\Content\View\Builder\ContentCreateViewBuilder; use EzSystems\RepositoryForms\Content\View\Builder\ContentEditViewBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -18,10 +19,15 @@ class ViewBuilderRegistryPass implements CompilerPassInterface { const VIEW_BUILDER_REGISTRY = 'ezpublish.view_builder.registry'; const VIEW_BUILDER_CONTENT_EDIT = ContentEditViewBuilder::class; + const VIEW_BUILDER_CONTENT_CREATE = ContentCreateViewBuilder::class; public function process(ContainerBuilder $container) { - if (!$container->hasDefinition(self::VIEW_BUILDER_REGISTRY) || !$container->hasDefinition(ContentEditViewBuilder::class)) { + if ( + !$container->hasDefinition(self::VIEW_BUILDER_REGISTRY) + || !$container->hasDefinition(self::VIEW_BUILDER_CONTENT_EDIT) + || !$container->hasDefinition(self::VIEW_BUILDER_CONTENT_CREATE) + ) { return; } @@ -29,6 +35,7 @@ public function process(ContainerBuilder $container) $viewBuilders = [ $container->getDefinition(self::VIEW_BUILDER_CONTENT_EDIT), + $container->getDefinition(self::VIEW_BUILDER_CONTENT_CREATE), ]; $registry->addMethodCall('addToRegistry', [$viewBuilders]); diff --git a/bundle/DependencyInjection/Configuration/Parser/ContentCreateView.php b/bundle/DependencyInjection/Configuration/Parser/ContentCreateView.php new file mode 100644 index 000000000..f7b9e54b2 --- /dev/null +++ b/bundle/DependencyInjection/Configuration/Parser/ContentCreateView.php @@ -0,0 +1,16 @@ +arrayNode('content_edit') - ->info('Content edit configuration') + ->info('Content edit configuration.') + ->setDeprecated('This key was deprecated in 2.1 and will be removed in 3.0. Please use siteaccess aware configuration.') ->children() ->arrayNode('templates') ->info('Content edit templates.') diff --git a/bundle/EzSystemsRepositoryFormsBundle.php b/bundle/EzSystemsRepositoryFormsBundle.php index 4835d697c..1715cc07a 100644 --- a/bundle/EzSystemsRepositoryFormsBundle.php +++ b/bundle/EzSystemsRepositoryFormsBundle.php @@ -13,6 +13,7 @@ use EzSystems\RepositoryFormsBundle\DependencyInjection\Compiler\LimitationFormMapperPass; use EzSystems\RepositoryFormsBundle\DependencyInjection\Compiler\LimitationValueMapperPass; use EzSystems\RepositoryFormsBundle\DependencyInjection\Compiler\ViewBuilderRegistryPass; +use EzSystems\RepositoryFormsBundle\DependencyInjection\Configuration\Parser\ContentCreateView; use EzSystems\RepositoryFormsBundle\DependencyInjection\Configuration\Parser\ContentEdit; use EzSystems\RepositoryFormsBundle\DependencyInjection\Configuration\Parser\ContentEditView; use EzSystems\RepositoryFormsBundle\DependencyInjection\Configuration\Parser\LimitationValueTemplates; @@ -38,6 +39,7 @@ public function build(ContainerBuilder $container) $eZExtension->addConfigParser(new UserEdit()); $eZExtension->addConfigParser(new LimitationValueTemplates()); $eZExtension->addConfigParser(new ContentEditView()); + $eZExtension->addConfigParser(new ContentCreateView()); $eZExtension->addDefaultSettings(__DIR__ . '/Resources/config', ['ezpublish_default_settings.yml']); } } diff --git a/bundle/Resources/config/ezpublish_default_settings.yml b/bundle/Resources/config/ezpublish_default_settings.yml index e504054b7..aca4109ca 100644 --- a/bundle/Resources/config/ezpublish_default_settings.yml +++ b/bundle/Resources/config/ezpublish_default_settings.yml @@ -11,3 +11,4 @@ parameters: - { template: 'EzSystemsRepositoryFormsBundle::limitation_values.html.twig', priority: 0 } ezsettings.default.content_edit_view: {} + ezsettings.default.content_create_view: {} diff --git a/bundle/Resources/config/routing.yml b/bundle/Resources/config/routing.yml index 8d07b960c..b4b519b51 100644 --- a/bundle/Resources/config/routing.yml +++ b/bundle/Resources/config/routing.yml @@ -4,6 +4,7 @@ ez_content_create_no_draft: _controller: ez_content_edit:createWithoutDraftAction options: expose: true + # @todo rename language to languageCode in 3.0 ez_content_draft_edit: path: /content/edit/draft/{contentId}/{versionNo}/{language}/{locationId} diff --git a/bundle/Resources/config/services.yml b/bundle/Resources/config/services.yml index f4821b24f..aa427d493 100644 --- a/bundle/Resources/config/services.yml +++ b/bundle/Resources/config/services.yml @@ -256,8 +256,6 @@ services: arguments: - "@ezpublish.api.service.content_type" - "@ezpublish.api.service.content" - - "@ezpublish.api.service.location" - - "@ezpublish.api.service.language" - "@ezrepoforms.action_dispatcher.content" parent: ezpublish.controller.base @@ -312,7 +310,6 @@ services: - [setViewTemplate, ['EzSystems\RepositoryForms\User\View\UserUpdateView', "$user_edit.templates.update$"]] - [setViewTemplate, ['EzSystems\RepositoryForms\User\View\UserRegisterFormView', "$user_registration.templates.form$"]] - [setViewTemplate, ['EzSystems\RepositoryForms\User\View\UserRegisterConfirmView', "$user_registration.templates.confirmation$"]] - - [setViewTemplate, ['EzSystems\RepositoryForms\Content\View\ContentCreateView', "$content_edit.templates.create$"]] - [setViewTemplate, ['EzSystems\RepositoryForms\Content\View\ContentCreateDraftView', "$content_edit.templates.create_draft$"]] - [setPagelayout, ["$pagelayout$"]] diff --git a/bundle/Resources/config/views.yml b/bundle/Resources/config/views.yml index 19213b20d..1bad237c1 100644 --- a/bundle/Resources/config/views.yml +++ b/bundle/Resources/config/views.yml @@ -4,6 +4,7 @@ services: autowire: true autoconfigure: true + # ContentEditView EzSystems\RepositoryForms\Content\View\Builder\ContentEditViewBuilder: arguments: - '@ezpublish.api.repository' @@ -12,7 +13,7 @@ services: - '$content_edit.templates.edit$' - '@ezrepoforms.action_dispatcher.content' - EzSystems\RepositoryForms\Content\View\Provider\Configured: + EzSystems\RepositoryForms\Content\View\Provider\ContentEditView\Configured: arguments: - '@ezplatform.repository_forms.content_edit_view.matcher_factory' tags: @@ -33,3 +34,34 @@ services: - '@ezpublish.api.service.content_type' tags: - { name: kernel.event_subscriber } + + # ContentCreateView + EzSystems\RepositoryForms\Content\View\Builder\ContentCreateViewBuilder: + arguments: + - '@ezpublish.api.repository' + - '@ezpublish.view.configurator' + - '@ezpublish.view.view_parameters.injector.dispatcher' + - '$content_edit.templates.create$' + - '@ezrepoforms.action_dispatcher.content' + + EzSystems\RepositoryForms\Content\View\Provider\ContentCreateView\Configured: + arguments: + - '@ezplatform.repository_forms.content_create_view.matcher_factory' + tags: + - {name: ezpublish.view_provider, type: 'EzSystems\RepositoryForms\Content\View\ContentCreateView', priority: 10} + + ezplatform.repository_forms.content_create_view.matcher_factory: + class: '%ezpublish.view.matcher_factory.class%' + arguments: + - '@ezpublish.api.repository' + - 'eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased' + calls: + - [setContainer, ['@service_container']] + - [setMatchConfig, ['$content_create_view$']] + + EzSystems\RepositoryForms\Content\View\Filter\ContentCreateViewFilter: + arguments: + - '@ezpublish.api.service.location' + - '@ezpublish.api.service.content_type' + tags: + - { name: kernel.event_subscriber } diff --git a/lib/Content/View/Builder/ContentCreateViewBuilder.php b/lib/Content/View/Builder/ContentCreateViewBuilder.php new file mode 100644 index 000000000..8867c3b6e --- /dev/null +++ b/lib/Content/View/Builder/ContentCreateViewBuilder.php @@ -0,0 +1,236 @@ +repository = $repository; + $this->viewConfigurator = $viewConfigurator; + $this->viewParametersInjector = $viewParametersInjector; + $this->defaultTemplate = $defaultTemplate; + $this->contentActionDispatcher = $contentActionDispatcher; + } + + public function matches($argument) + { + return 'ez_content_edit:createWithoutDraftAction' === $argument; + } + + /** + * @param array $parameters + * + * @return \EzSystems\RepositoryForms\Content\View\ContentCreateView + * + * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException + */ + public function buildView(array $parameters) + { + // @todo improve default templates injection + $view = new ContentCreateView($this->defaultTemplate); + + $language = $this->resolveLanguage($parameters); + $location = $this->resolveLocation($parameters); + $contentType = $this->resolveContentType($parameters, $language); + $form = $parameters['form']; + + if ($form->isValid() && null !== $form->getClickedButton()) { + $this->contentActionDispatcher->dispatchFormAction( + $form, + $form->getData(), + $form->getClickedButton()->getName(), + ['referrerLocation' => $location] + ); + + if ($response = $this->contentActionDispatcher->getResponse()) { + $view->setResponse($response); + } + } + + $view->setContentType($contentType); + $view->setLanguage($language); + $view->setLocation($location); + $view->setForm($form); + + $view->addParameters([ + 'contentType' => $contentType, + 'language' => $language, + 'parentLocation' => $location, // @todo: rename to `location` for consistency (3.0) + 'form' => $form->createView(), + ]); + + $this->viewParametersInjector->injectViewParameters($view, $parameters); + $this->viewConfigurator->configure($view); + + return $view; + } + + /** + * Loads a visible Location. + * + * @param int $locationId + * + * @return \eZ\Publish\API\Repository\Values\Content\Location + * + * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + */ + private function loadLocation(int $locationId): Location + { + return $this->repository->getLocationService()->loadLocation($locationId); + } + + /** + * Loads Language with code $languageCode. + * + * @param string $languageCode + * + * @return \eZ\Publish\API\Repository\Values\Content\Language + * + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + */ + private function loadLanguage(string $languageCode): Language + { + return $this->repository->getContentLanguageService()->loadLanguage($languageCode); + } + + /** + * Loads ContentType with identifier $contentTypeIdentifier. + * + * @param string $contentTypeIdentifier + * @param array $prioritizedLanguages + * + * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType + * + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + */ + private function loadContentType(string $contentTypeIdentifier, array $prioritizedLanguages = []): ContentType + { + return $this->repository->getContentTypeService()->loadContentTypeByIdentifier( + $contentTypeIdentifier, + $prioritizedLanguages + ); + } + + /** + * @param array $parameters + * + * @return \eZ\Publish\API\Repository\Values\Content\Language + * + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException + */ + private function resolveLanguage(array $parameters): Language + { + if (isset($parameters['languageCode'])) { + return $this->loadLanguage($parameters['languageCode']); + } + + if (isset($parameters['language'])) { + if (is_string($parameters['language'])) { + // @todo BC: route parameter should be called languageCode but it won't happen until 3.0 + return $this->loadLanguage($parameters['language']); + } + + return $parameters['language']; + } + + throw new InvalidArgumentException('Language', + 'No language information provided. Are you missing language or languageCode parameters'); + } + + /** + * @param array $parameters + * @param \eZ\Publish\API\Repository\Values\Content\Language $language + * + * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType + * + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException + */ + private function resolveContentType(array $parameters, Language $language): ContentType + { + if (isset($parameters['contentType'])) { + return $parameters['contentType']; + } + + if (isset($parameters['contentTypeIdentifier'])) { + return $this->loadContentType($parameters['contentTypeIdentifier'], [$language->languageCode]); + } + + throw new InvalidArgumentException( + 'ContentType', + 'No content type could be loaded from parameters' + ); + } + + /** + * @param array $parameters + * + * @return \eZ\Publish\API\Repository\Values\Content\Location + * + * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException + */ + private function resolveLocation(array $parameters): Location + { + if (isset($parameters['parentLocation'])) { + return $parameters['parentLocation']; + } + + if (isset($parameters['parentLocationId'])) { + return $this->loadLocation((int) $parameters['parentLocationId']); + } + + throw new InvalidArgumentException( + 'ParentLocation', + 'Unable to load parent location from parameters' + ); + } +} diff --git a/lib/Content/View/ContentCreateView.php b/lib/Content/View/ContentCreateView.php index 3799901b5..fe8e3ed08 100644 --- a/lib/Content/View/ContentCreateView.php +++ b/lib/Content/View/ContentCreateView.php @@ -1,12 +1,95 @@ contentType = $contentType; + } + + /** + * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType + */ + public function getContentType(): ContentType + { + return $this->contentType; + } + + /** + * @param \eZ\Publish\API\Repository\Values\Content\Location $location + */ + public function setLocation(Location $location) + { + $this->location = $location; + } + + /** + * @return \eZ\Publish\API\Repository\Values\Content\Location + */ + public function getLocation(): Location + { + return $this->location; + } + + /** + * @return \eZ\Publish\API\Repository\Values\Content\Language + */ + public function getLanguage(): Language + { + return $this->language; + } + + /** + * @param \eZ\Publish\API\Repository\Values\Content\Language $language + */ + public function setLanguage(Language $language) + { + $this->language = $language; + } + + /** + * @return \Symfony\Component\Form\FormInterface + */ + public function getForm(): FormInterface + { + return $this->form; + } + + /** + * @param \Symfony\Component\Form\FormInterface $form + */ + public function setForm(FormInterface $form) + { + $this->form = $form; + } } diff --git a/lib/Content/View/ContentTypeValueView.php b/lib/Content/View/ContentTypeValueView.php new file mode 100644 index 000000000..debaaace0 --- /dev/null +++ b/lib/Content/View/ContentTypeValueView.php @@ -0,0 +1,21 @@ +locationService = $locationService; + $this->contentTypeService = $contentTypeService; + $this->formFactory = $formFactory; + } + + public static function getSubscribedEvents() + { + return [ViewEvents::FILTER_BUILDER_PARAMETERS => 'handleContentCreateForm']; + } + + /** + * @param \eZ\Publish\Core\MVC\Symfony\View\Event\FilterViewBuilderParametersEvent $event + * + * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException + * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + */ + public function handleContentCreateForm(FilterViewBuilderParametersEvent $event) + { + if ('ez_content_edit:createWithoutDraftAction' !== $event->getParameters()->get('_controller')) { + return; + } + + $request = $event->getRequest(); + $languageCode = $request->attributes->get('language'); + $contentType = $this->contentTypeService->loadContentTypeByIdentifier( + $request->attributes->get('contentTypeIdentifier') + ); + $location = $this->locationService->loadLocation($request->attributes->get('parentLocationId')); + + $contentCreateData = $this->resolveContentCreateData($contentType, $location, $languageCode); + $form = $this->resolveContentCreateForm($contentCreateData, $languageCode); + + $event->getParameters()->add(['form' => $form->handleRequest($request)]); + } + + /** + * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType + * @param \eZ\Publish\API\Repository\Values\Content\Location $location + * @param string $languageCode + * + * @return \EzSystems\RepositoryForms\Data\Content\ContentCreateData + */ + private function resolveContentCreateData( + ContentType $contentType, + Location $location, + string $languageCode + ): ContentCreateData { + $contentCreateMapper = new ContentCreateMapper(); + + return $contentCreateMapper->mapToFormData( + $contentType, + [ + 'mainLanguageCode' => $languageCode, + 'parentLocation' => $this->locationService->newLocationCreateStruct($location->id), + ] + ); + } + + /** + * @param \EzSystems\RepositoryForms\Data\Content\ContentCreateData $contentCreateData + * @param string $languageCode + * + * @return \Symfony\Component\Form\FormInterface + * + * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException + */ + private function resolveContentCreateForm( + ContentCreateData $contentCreateData, + string $languageCode + ): FormInterface { + return $this->formFactory->create(ContentEditType::class, $contentCreateData, [ + 'languageCode' => $languageCode, + 'mainLanguageCode' => $languageCode, + 'drafts_enabled' => true, + ]); + } +} diff --git a/lib/Content/View/Provider/ContentCreateView/Configured.php b/lib/Content/View/Provider/ContentCreateView/Configured.php new file mode 100644 index 000000000..270f8cf53 --- /dev/null +++ b/lib/Content/View/Provider/ContentCreateView/Configured.php @@ -0,0 +1,67 @@ +matcherFactory = $matcherFactory; + } + + public function getView(View $view) + { + if (($configHash = $this->matcherFactory->match($view)) === null) { + return null; + } + + return $this->buildContentCreateView($configHash); + } + + /** + * Builds a ContentCreateView object from $viewConfig. + * + * @param array $viewConfig + * + * @return \EzSystems\RepositoryForms\Content\View\ContentCreateView + */ + protected function buildContentCreateView(array $viewConfig): ContentCreateView + { + $view = new ContentCreateView(); + $view->setConfigHash($viewConfig); + if (isset($viewConfig['template'])) { + $view->setTemplateIdentifier($viewConfig['template']); + } + if (isset($viewConfig['controller'])) { + $view->setControllerReference(new ControllerReference($viewConfig['controller'])); + } + if (isset($viewConfig['params']) && is_array($viewConfig['params'])) { + $view->addParameters($viewConfig['params']); + } + + return $view; + } +} diff --git a/lib/Content/View/Provider/Configured.php b/lib/Content/View/Provider/ContentEditView/Configured.php similarity index 96% rename from lib/Content/View/Provider/Configured.php rename to lib/Content/View/Provider/ContentEditView/Configured.php index b0c6d4c02..ebca09f47 100644 --- a/lib/Content/View/Provider/Configured.php +++ b/lib/Content/View/Provider/ContentEditView/Configured.php @@ -6,7 +6,7 @@ */ declare(strict_types=1); -namespace EzSystems\RepositoryForms\Content\View\Provider; +namespace EzSystems\RepositoryForms\Content\View\Provider\ContentEditView; use eZ\Publish\Core\MVC\Symfony\Matcher\MatcherFactoryInterface; use eZ\Publish\Core\MVC\Symfony\View\View; diff --git a/lib/EventListener/UserEditListener.php b/lib/EventListener/UserEditListener.php index 24164badf..be7ea6011 100644 --- a/lib/EventListener/UserEditListener.php +++ b/lib/EventListener/UserEditListener.php @@ -76,6 +76,7 @@ public function onControllerUserCreate(FilterControllerEvent $event) return; } + $event->getRequest()->attributes->set('_controller', [$this->userController, 'createAction']); $event->setController([$this->userController, 'createAction']); } } @@ -101,6 +102,7 @@ public function onControllerUserEdit(FilterControllerEvent $event) return; } + $event->getRequest()->attributes->set('_controller', [$this->userController, 'editAction']); $event->setController([$this->userController, 'editAction']); } }