Handles action on collection details page

@param \Symfony\Component\HttpFoundation\Request $request

@return \Symfony\Component\HttpFoundation\RedirectResponse
2999
public function handleCollectionAction(Request $request)
    {
        $this->denyAccessUnlessGranted('ez:infocollector:read');

        $collectionId = $request->request->get('CollectionId');
        $contentId = $request->request->get('ContentId');
        $fields = $request->request->get('FieldId', []);
        $count = count($fields);

        if (
            ($request->request->has('AnonymizeFieldAction') || $request->request->has('DeleteFieldAction'))
            && empty($fields)
        ) {
            $this->addFlashMessage('errors', 'fields_not_selected');

            return $this->redirectToRoute('netgen_information_collection.route.admin.view', ['collectionId' => $collectionId]);
        }

        if ($request->request->has('DeleteFieldAction')) {
            $query = new Query([
                'contentId' => $contentId,
                'collectionId' => $collectionId,
                'fields' => $fields,
            ]);
            $this->service->deleteCollectionFields($query);

            $this->addFlashMessage('success', 'field_removed', $count);

            return $this->redirectToRoute('netgen_information_collection.route.admin.view', ['collectionId' => $collectionId]);
        }

        if ($request->request->has('AnonymizeFieldAction')) {
            $this->anonymizer->anonymizeCollection($collectionId, $fields);

            $this->addFlashMessage('success', 'field_anonymized', $count);

            return $this->redirectToRoute('netgen_information_collection.route.admin.view', ['collectionId' => $collectionId]);
        }

        if ($request->request->has('DeleteCollectionAction')) {
            $query = new Query([
                'contentId' => $contentId,
                'collections' => [$collectionId],
            ]);
            $this->service->deleteCollections($query);

            $this->addFlashMessage("success", "collection_removed");

            return $this->redirectToRoute('netgen_information_collection.route.admin.collection_list', ['contentId' => $contentId]);

        }

        if ($request->request->has('AnonymizeCollectionAction')) {
            $this->anonymizer->anonymizeCollection($collectionId);

            $this->addFlashMessage("success", "collection_anonymized");

            return $this->redirectToRoute('netgen_information_collection.route.admin.view', ['collectionId' => $collectionId]);
        }

        $this->addFlashMessage('error', 'something_went_wrong');

        return $this->redirectToRoute('netgen_information_collection.route.admin.view', ['collectionId' => $collectionId]);
    }
576126
public function handleRequest(Request $request): void
    {
        $this->getForm()->handleRequest($request);
        $this->handleForm($request->get('page'));
    }
186491
public function deleteCollectionAction(Request $request)
    {
        if (null === $uids = $request->get('uids', null)) {
            throw new BadRequestHttpException('uid is missing.');
        }

        $result = [];
        $statusCode = 204;
        $pages = $this->getPageRepository()->findBy(['_uid' => $uids]);
        foreach ($pages as $page) {
            try {
                if ($page->isDeleted()) {
                    $this->hardDelete($page);
                } else {
                    $this->softDelete($page);
                }

                $result[] = [
                    'uid'        => $page->getUid(),
                    'statusCode' => 204,
                    'message'    => 'OK',
                ];
            } catch (AccessDeniedException $e) {
                $result[] = [
                    'uid'        => $page->getUid(),
                    'statusCode' => 401,
                    'message'    => $e->getMessage(),
                ];
                $statusCode = ($statusCode < 401) ? 401 : $statusCode;
            } catch (\Exception $e) {
                if ($e instanceof BadRequestHttpException || $e instanceof InsufficientAuthenticationException) {
                    $result[] = [
                        'uid'        => $page->getUid(),
                        'statusCode' => 403,
                        'message'    => $e->getMessage(),
                    ];
                    $statusCode = ($statusCode < 403) ? 403 : $statusCode;
                } else {
                    $result[] = [
                        'uid'        => $page->getUid(),
                        'statusCode' => 500,
                        'message'    => $e->getMessage(),
                    ];
                    $statusCode = ($statusCode < 500) ? 500 : $statusCode;
                }
            }
        }

        $this->getEntityManager()->flush();

        return $this->createJsonResponse($result, $statusCode);
    }
1192515
public function addAction(Request $request): Response
    {
        $form = $this->formFactory->addCustomUrl();
        $form->handleRequest($request);

        /** @var CustomUrlAddData $data */
        $data = $form->getData();
        $location = $data->getLocation();

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (CustomUrlAddData $data) {
                $this->urlAliasService->createUrlAlias(
                    $data->getLocation(),
                    $data->getPath(),
                    $data->getLanguage()->languageCode,
                    $data->isRedirect()
                );

                return $this->redirectToLocation($data->getLocation(), UrlsTab::URI_FRAGMENT);
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        if ($location) {
            return $this->redirectToLocation($location, UrlsTab::URI_FRAGMENT);
        }

        return $this->redirectToRoute('ezplatform.dashboard');
    }
451392
public function ajaxIndexAction(Request $request): Response
    {
        if (!$request->isXmlHttpRequest()) {
            return $this->redirectToAction('index');
        }
        
        $attributeGroupId = (int)$request->request->get('id');
        $attributeGroup   = $this->getManager()->findAttributeGroup($attributeGroupId);
        
        return $this->jsonResponse([
            'attributes' => $this->getManager()->getRepository()->getAttributeSet($attributeGroup),
        ]);
    }
407196
public function listAction(Request $request)
    {
        return $this->render('SynapsePageBundle:Admin/Page:list.html.twig', array(
            'pages' => $this->container->get('synapse.page.loader')->retrieveAll(),
            'page_rendering_route' => $this->container->getParameter('synapse.page.rendering_route'),
        ));
    }
214392
public function handle(Request $request)
    {
        $response = new Response();
        $response = $this->executePassiveActions($request, $response);
        $response = $this->executeAction($request, $response);

        if ($response->isClientError() || $response->isServerError()) {
            return $this->handleError($request, $response);
        }

        return $response;
    }
1058787
public function removeAction(Request $request): Response
    {
        $form = $this->formFactory->removeBookmark(
            new BookmarkRemoveData()
        );
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (BookmarkRemoveData $data) {
                foreach ($data->getBookmarks() as $locationId => $selected) {
                    $this->bookmarkService->deleteBookmark(
                        $this->locationService->loadLocation($locationId)
                    );
                }

                return $this->redirectToRoute('ezplatform.bookmark.list');
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->redirectToRoute('ezplatform.bookmark.list');
    }
968561
public function addAction(Request $request): Response
    {
        $form = $this->formFactory->addTranslation();
        $form->handleRequest($request);

        /** @var TranslationAddData $data */
        $data = $form->getData();
        $location = $data->getLocation();

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (TranslationAddData $data) {
                $location = $data->getLocation();
                $contentInfo = $location->getContentInfo();
                $language = $data->getLanguage();
                $baseLanguage = $data->getBaseLanguage();

                return new RedirectResponse($this->generateUrl('ezplatform.content.translate', [
                    'contentId' => $contentInfo->id,
                    'fromLanguageCode' => null !== $baseLanguage ? $baseLanguage->languageCode : null,
                    'toLanguageCode' => $language->languageCode,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        $redirectionUrl = null !== $location
            ? $this->generateUrl('_ezpublishLocation', ['locationId' => $location->id])
            : $this->generateUrl('ezplatform.dashboard');

        return $this->redirect($redirectionUrl);
    }
415791
public function moveDownAction(Request $request)
    {
        $context = $this->loadContext($request);

        $resource = $context->getResource();

        $this->isGranted('EDIT', $resource);

        $repo = $this->getRepository();
        $repo->moveDown($resource, 1);

        return $this->redirectToReferer($this->generateUrl(
            $this->config->getRoute('list'),
            $context->getIdentifiers()
        ));
    }
826038
public function listAction(Request $request): Response
    {
        $page = $request->query->get('page') ?? 1;

        $pagerfanta = new Pagerfanta(
            new ArrayAdapter($this->roleService->loadRoles())
        );

        $pagerfanta->setMaxPerPage($this->defaultPaginationLimit);
        $pagerfanta->setCurrentPage(min($page, $pagerfanta->getNbPages()));

        /** @var \eZ\Publish\API\Repository\Values\User\Role[] $sectionList */
        $roles = $pagerfanta->getCurrentPageResults();

        $rolesNumbers = array_column($roles, 'id');

        $rolesDeleteData = new RolesDeleteData(
            array_combine($rolesNumbers, array_fill_keys($rolesNumbers, false))
        );

        $rolesDeleteForm = $this->formFactory->deleteRoles($rolesDeleteData);

        return $this->render('@ezdesign/admin/role/list.html.twig', [
            'form_roles_delete' => $rolesDeleteForm->createView(),
            'pager' => $pagerfanta,
            'can_create' => $this->isGranted(new Attribute('role', 'create')),
            'can_delete' => $this->isGranted(new Attribute('role', 'delete')),
            'can_update' => $this->isGranted(new Attribute('role', 'update')),
            'can_assign' => $this->isGranted(new Attribute('role', 'assign')),
        ]);
    }
105141
protected function handleAction($request, $action)
    {
        foreach ($request->latestParams() as $k => $v) {
            if ($v || !isset($this->urlParams[$k])) {
                $this->urlParams[$k] = $v;
            }
        }

        $this->action = $action;
        $this->requestParams = $request->requestVars();

        if ($this->hasMethod($action)) {
            $result = parent::handleAction($request, $action);

            // If the action returns an array, customise with it before rendering the template.
            if (is_array($result)) {
                return $this->getViewer($action)->process($this->customise($result));
            } else {
                return $result;
            }
        }

        // Fall back to index action with before/after handlers
        $beforeResult = $this->extend('beforeCallActionHandler', $request, $action);
        if ($beforeResult) {
            return reset($beforeResult);
        }

        $result = $this->getViewer($action)->process($this);

        $afterResult = $this->extend('afterCallActionHandler', $request, $action, $result);
        if ($afterResult) {
            return reset($afterResult);
        }

        return $result;
    }
893220
public function indexAction(/** @noinspection PhpUnusedParameterInspection */
        Request $request
    ) {
        /** @var array $families */
        $families = $this->admin->getOption('families', []);
        /* @noinspection LoopWhichDoesNotLoopInspection */
        foreach ($families as $family => $options) {
            return $this->redirectToAction('list', ['familyCode' => $family]);
        }

        return $this->renderAction(
            [
                'admin' => $this->admin,
            ]
        );
    }
1013706
public function dispatch(Request $request) {

        $uri = $request->uri();
        $method = $request->method();

        if (in_array($uri, self::$routes)) {
            if (self::$methods[$uri] == $method || self::$methods[$uri] == 'ANY') {
                if (is_object(self::$callbacks[$uri])) {
                     call_user_func(self::$callbacks[$uri]);
                } else {
                    $s = explode('@', self::$callbacks[$uri]);
                    call_user_func(array((new $s[0]), $s[1]));
                }
            }
        } else {
            header($_SERVER['SERVER_PROTOCOL']." 404 Not Found");
            echo '404';
        }
    }
430583
public function handle($request)
    {
        $entity = $this->repository()->findById($request->getId());
        $this->authorize($request, $entity);

        $item = $this->getProperty($entity, $this->field());
        $this->related()->getEntityManager()->remove($item);
        $this->setProperty($entity, $this->field(), null);

        $this->repository()->getEntityManager()->flush();

        return $this->response()->noContent();
    }
1327567
public function batchDeleteAction(Request $request)
    {
        $this->checkIfUserHasPermission(Permission::CREATE_DELETE);

        $this->getParentEntityDefinition($request);

        $this->getEventDispatcher()->dispatch(
            Events::PRE_CRUD_CONTROLLER_ACTION,
            new CrudControllerActionEvent($this->meta, __FUNCTION__)
        );

        $form = $this->getAdminFormFactory()->createBatchDeleteForm($this->entityClass)->handleRequest($request);
        $entities = $form->get('entities')->getData();

        if ($entities instanceof Collection) {
            $entities = $entities->toArray();
        }
        if (empty($entities)) {
            throw new ControllerException(
                sprintf('Unable to handle batch delete form for entity class "%s": entity array is empty.', $this->entityClass)
            );
        }
        if ($this->getFormHandler()->handleBatchDeleteForm($form, $entities)) {
            $eventDispatcher = $this->getEventDispatcher();
            $user            = $this->getUser();

            foreach ($entities as $entity) {
                $eventDispatcher->dispatch(CrudEvents::DELETED, new DeletedEvent($user, $entity));
            }

            return $this->redirect($this->getAdminRouter()->generate(reset($entities), $this->entityClass, AdminRouter::TYPE_INDEX));
        }

        $url = $request->headers->get(
            'referer',
            $this->getAdminRouter()->generate(reset($entities), $this->entityClass, AdminRouter::TYPE_INDEX)
        );

        return $this->redirect($url);
    }
962081
public function dispatch(Request $request)
    {
        // Create the action instance
        $action = $this->resolveAction($request->getHandler());

        return $action->execute($request->getParameters());
    }