From 063ac0503f0df7623a445a00bd375271ff1fecec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Mon, 15 Jun 2020 14:09:12 +0200 Subject: [PATCH 1/3] EZP-31651: Injected edit form into new view --- composer.json | 1 + src/bundle/Resources/config/services.yaml | 6 +++ src/bundle/Resources/config/views.yaml | 6 +++ ...SearchListViewFilterParametersListener.php | 52 +++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 src/lib/EventListener/EditFormSearchListViewFilterParametersListener.php diff --git a/composer.json b/composer.json index ae77c70d01..9fba98f53c 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "ezsystems/ezplatform-user": "^2.0@dev", "ezsystems/ezplatform-richtext": "^2.0@dev", "ezsystems/ezplatform-rest": "^1.0@dev", + "ezsystems/ezplatform-search": "^1.0@dev", "babdev/pagerfanta-bundle": "^2.1", "knplabs/knp-menu-bundle": "^3.0", "mck89/peast": "^1.9", diff --git a/src/bundle/Resources/config/services.yaml b/src/bundle/Resources/config/services.yaml index 523a995571..98c1deeec0 100644 --- a/src/bundle/Resources/config/services.yaml +++ b/src/bundle/Resources/config/services.yaml @@ -129,3 +129,9 @@ services: EzSystems\EzPlatformAdminUi\UI\Service\DateTimeFormatter: ~ EzSystems\EzPlatformAdminUi\UI\Service\DateTimeFormatterInterface: '@EzSystems\EzPlatformAdminUi\UI\Service\DateTimeFormatter' + + EzSystems\EzPlatformAdminUi\EventListener\EditFormSearchListViewFilterParametersListener: + arguments: + $formFactory: '@form.factory' + tags: + - {name: kernel.event_subscriber} diff --git a/src/bundle/Resources/config/views.yaml b/src/bundle/Resources/config/views.yaml index e34461d3de..fd5c16e739 100644 --- a/src/bundle/Resources/config/views.yaml +++ b/src/bundle/Resources/config/views.yaml @@ -51,6 +51,12 @@ system: match: Identifier: [full_datetime_format, short_datetime_format] + search_list_view: + full: + ezplatform_admin_ui: + template: '@ezdesign/ui/search/index.html.twig' + match: true + default: fielddefinition_edit_templates: - { template: '@ezdesign/content_type/field_types.html.twig', priority: 0 } diff --git a/src/lib/EventListener/EditFormSearchListViewFilterParametersListener.php b/src/lib/EventListener/EditFormSearchListViewFilterParametersListener.php new file mode 100644 index 0000000000..6990a6dfb7 --- /dev/null +++ b/src/lib/EventListener/EditFormSearchListViewFilterParametersListener.php @@ -0,0 +1,52 @@ +formFactory = $formFactory; + } + + public static function getSubscribedEvents(): array + { + return [ + ViewEvents::FILTER_VIEW_PARAMETERS => ['onFilterViewParameters', 10], + ]; + } + + public function onFilterViewParameters(FilterViewParametersEvent $event) + { + $view = $event->getView(); + + if (!$view instanceof SearchListView) { + return; + } + + $editForm = $this->formFactory->create( + ContentEditType::class, + new ContentEditData(), + ); + + $event->getParameterBag()->add([ + 'form_edit' => $editForm->createView(), + ]); + } +} From 0aaf8b9a5ad58db6641ec5c5d06868a2e4669e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Mon, 15 Jun 2020 14:09:48 +0200 Subject: [PATCH 2/3] EZP-31651: Deprecate current search controller --- src/bundle/Controller/SearchController.php | 3 +++ src/bundle/Resources/config/routing.yaml | 10 ---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/bundle/Controller/SearchController.php b/src/bundle/Controller/SearchController.php index ccfb051e03..122f4e3e4d 100644 --- a/src/bundle/Controller/SearchController.php +++ b/src/bundle/Controller/SearchController.php @@ -21,6 +21,9 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +/** + * @deprecated, use Ibexa\Platform\Bundle\SearchBundle for customizable search feature. + */ class SearchController extends Controller { /** @var \eZ\Publish\API\Repository\SearchService */ diff --git a/src/bundle/Resources/config/routing.yaml b/src/bundle/Resources/config/routing.yaml index af03f02c44..3f57730bda 100644 --- a/src/bundle/Resources/config/routing.yaml +++ b/src/bundle/Resources/config/routing.yaml @@ -588,16 +588,6 @@ ezplatform.content.draft.create: options: expose: true -# -# Search -# - -ezplatform.search: - path: /search - methods: ['GET'] - defaults: - _controller: 'EzSystems\EzPlatformAdminUiBundle\Controller\SearchController::searchAction' - # # Link manager # From 145215c8dec63b76b447a26c9fee5258b0b533ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Tue, 16 Jun 2020 09:17:56 +0200 Subject: [PATCH 3/3] EZP-31651: Dropped SearchController.php --- src/bundle/Controller/SearchController.php | 174 ------------------ .../config/services/controllers.yaml | 10 - 2 files changed, 184 deletions(-) delete mode 100644 src/bundle/Controller/SearchController.php diff --git a/src/bundle/Controller/SearchController.php b/src/bundle/Controller/SearchController.php deleted file mode 100644 index 122f4e3e4d..0000000000 --- a/src/bundle/Controller/SearchController.php +++ /dev/null @@ -1,174 +0,0 @@ -searchService = $searchService; - $this->pagerSearchContentToDataMapper = $pagerSearchContentToDataMapper; - $this->formFactory = $formFactory; - $this->sectionService = $sectionService; - $this->contentTypeService = $contentTypeService; - $this->searchQueryType = $searchQueryType; - $this->configResolver = $configResolver; - } - - /** - * Renders the simple search form and search results. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * - * @return \Symfony\Component\HttpFoundation\Response - * - * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @throws \InvalidArgumentException - */ - public function searchAction(Request $request): Response - { - $search = $request->query->get('search'); - $limit = $search['limit'] ?? $this->configResolver->getParameter('pagination.search_limit'); - $page = $search['page'] ?? 1; - $query = $search['query'] ?? ''; - $section = null; - $creator = null; - $contentTypes = []; - $lastModified = $search['last_modified'] ?? []; - $created = $search['created'] ?? []; - $subtree = $search['subtree'] ?? null; - $searchLanguage = null; - - if (!empty($search['section'])) { - $section = $this->sectionService->loadSection($search['section']); - } - if (!empty($search['content_types']) && is_array($search['content_types'])) { - foreach ($search['content_types'] as $identifier) { - $contentTypes[] = $this->contentTypeService->loadContentTypeByIdentifier($identifier); - } - } - - $form = $this->formFactory->createSearchForm( - new SearchData( - $limit, - $page, - $query, - $section, - $contentTypes, - $lastModified, - $created, - $creator, - $subtree, - $searchLanguage - ), - 'search', - [ - 'method' => Request::METHOD_GET, - 'csrf_protection' => false, - ] - ); - - $form->handleRequest($request); - - if ($form->isSubmitted() && $form->isValid()) { - $data = $form->getData(); - $queryString = $data->getQuery(); - $searchLanguageCode = ($data->getSearchLanguage() instanceof Language) - ? $data->getSearchLanguage()->languageCode - : null; - $languageFilter = $this->getSearchLanguageFilter($searchLanguageCode, $queryString); - - $pagerfanta = new Pagerfanta( - new ContentSearchHitAdapter( - $this->searchQueryType->getQuery(['search_data' => $data]), - $this->searchService, - $languageFilter - ) - ); - $pagerfanta->setMaxPerPage($data->getLimit()); - $pagerfanta->setCurrentPage(min($data->getPage(), $pagerfanta->getNbPages())); - - $editForm = $this->formFactory->contentEdit( - new ContentEditData() - ); - - return $this->render('@ezdesign/ui/search/index.html.twig', [ - 'results' => $this->pagerSearchContentToDataMapper->map($pagerfanta), - 'form' => $form->createView(), - 'pager' => $pagerfanta, - 'form_edit' => $editForm->createView(), - 'user_content_type_identifier' => $this->configResolver->getParameter('user_content_type_identifier'), - ]); - } - - return $this->render('@ezdesign/ui/search/index.html.twig', [ - 'form' => $form->createView(), - 'user_content_type_identifier' => $this->configResolver->getParameter('user_content_type_identifier'), - ]); - } - - private function getSearchLanguageFilter(?string $languageCode, ?string $queryString): array - { - $filter = [ - 'languages' => !empty($languageCode) ? [$languageCode] : [], - 'useAlwaysAvailable' => true, - ]; - - if (!empty($queryString)) { - $filter['excludeTranslationsFromAlwaysAvailable'] = false; - } - - return $filter; - } -} diff --git a/src/bundle/Resources/config/services/controllers.yaml b/src/bundle/Resources/config/services/controllers.yaml index e5e74fb445..d70ffbb048 100644 --- a/src/bundle/Resources/config/services/controllers.yaml +++ b/src/bundle/Resources/config/services/controllers.yaml @@ -53,16 +53,6 @@ services: tags: - controller.service_arguments - EzSystems\EzPlatformAdminUiBundle\Controller\SearchController: - parent: EzSystems\EzPlatformAdminUiBundle\Controller\Controller - autowire: true - lazy: true - arguments: - $searchQueryType: '@EzSystems\EzPlatformAdminUi\QueryType\SearchQueryType' - $configResolver: '@ezpublish.config.resolver' - tags: - - controller.service_arguments - EzSystems\EzPlatformAdminUiBundle\Controller\User\UserDeleteController: parent: EzSystems\EzPlatformAdminUiBundle\Controller\Controller autowire: true