public function updateVisibilityAction(Request $request): Response
    {
        $form = $this->formFactory->updateVisibilityLocation();
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $data = $form->getData();

            /** @var \eZ\Publish\API\Repository\Values\Content\Location $location */
            $location = $data->getLocation();
            $hidden = $data->getHidden();

            try {
                /** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo */
                $contentInfo = $location->getContentInfo();

                if ($hidden) {
                    $this->locationService->hideLocation($location);
                    $message = $this->translator->trans(
                        /** @Desc("Location '%name%' hidden.") */
                        'location.update_success.success.hidden',
                        ['%name%' => $contentInfo->name],
                        'location'
                    );
                } else {
                    $this->locationService->unhideLocation($location);
                    $message = $this->translator->trans(
                        /** @Desc("Location '%name%' unhidden.") */
                        'location.update_success.success.unhidden',
                        ['%name%' => $contentInfo->name],
                        'location'
                    );
                }
            } catch (APIRepositoryUnauthorizedException $e) {
                return new JsonResponse(['errors' => [$e->getMessage()]], Response::HTTP_UNAUTHORIZED);
            }
        } else {
            $errors = [];
            foreach ($form->getErrors(true, true) as $formError) {
                $errors[] = $formError->getMessage();
            }

            return new JsonResponse(['errors' => $errors], Response::HTTP_UNPROCESSABLE_ENTITY);
        }

        return new JsonResponse(['message' => $message]);
    }
public function updateVisibilityAction(Request $request): Response
    {
        $form = $this->formFactory->updateVisibilityLocation();
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $data = $form->getData();

            /** @var \eZ\Publish\API\Repository\Values\Content\Location $location */
            $location = $data->getLocation();
            $hidden = $data->getHidden();

            try {
                /** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo */
                $contentInfo = $location->getContentInfo();

                if ($hidden) {
                    $this->locationService->hideLocation($location);
                    $message = $this->translator->trans(
                        /** @Desc("Location '%name%' hidden.") */
                        'location.update_success.success.hidden',
                        ['%name%' => $contentInfo->name],
                        'location'
                    );
                } else {
                    $this->locationService->unhideLocation($location);
                    $message = $this->translator->trans(
                        /** @Desc("Location '%name%' unhidden.") */
                        'location.update_success.success.unhidden',
                        ['%name%' => $contentInfo->name],
                        'location'
                    );
                }
            } catch (APIRepositoryUnauthorizedException $e) {
                return new JsonResponse(['errors' => [$e->getMessage()]], Response::HTTP_UNAUTHORIZED);
            }
        } else {
            $errors = [];
            foreach ($form->getErrors(true, true) as $formError) {
                $errors[] = $formError->getMessage();
            }

            return new JsonResponse(['errors' => $errors], Response::HTTP_UNPROCESSABLE_ENTITY);
        }

        return new JsonResponse(['message' => $message]);
    }
public function updateVisibilityAction ( Request $ request ) : Response { $ form = $ this -> formFactory -> updateVisibilityLocation ( ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { $ data = $ form -> getData ( ) ; /** @var \eZ\Publish\API\Repository\Values\Content\Location $location */ $ location = $ data -> getLocation ( ) ; $ hidden = $ data -> getHidden ( ) ; try { /** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo */ $ contentInfo = $ location -> getContentInfo ( ) ; if ( $ hidden ) { $ this -> locationService -> hideLocation ( $ location ) ; $ message = $ this -> translator -> trans ( /** @Desc("Location '%name%' hidden.") */ 'location.update_success.success.hidden' , [ '%name%' => $ contentInfo -> name ] , 'location' ) ; } else { $ this -> locationService -> unhideLocation ( $ location ) ; $ message = $ this -> translator -> trans ( /** @Desc("Location '%name%' unhidden.") */ 'location.update_success.success.unhidden' , [ '%name%' => $ contentInfo -> name ] , 'location' ) ; } } catch ( APIRepositoryUnauthorizedException $ e ) { return new JsonResponse ( [ 'errors' => [ $ e -> getMessage ( ) ] ] , Response :: HTTP_UNAUTHORIZED ) ; } } else { $ errors = [ ] ; foreach ( $ form -> getErrors ( true , true ) as $ formError ) { $ errors [ ] = $ formError -> getMessage ( ) ; } return new JsonResponse ( [ 'errors' => $ errors ] , Response :: HTTP_UNPROCESSABLE_ENTITY ) ; } return new JsonResponse ( [ 'message' => $ message ] ) ; }
Handles toggling visibility location of a content item based on submitted form.

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

@return \Symfony\Component\HttpFoundation\Response
Handles toggling visibility location of a content item based on submitted form .