public function addAction(Request $request): Response
    {
        $form = $this->formFactory->addLocation(
            new ContentLocationAddData()
        );
        $form->handleRequest($request);

        $contentInfo = $form->getData()->getContentInfo();

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (ContentLocationAddData $data) {
                $contentInfo = $data->getContentInfo();

                foreach ($data->getNewLocations() as $newLocation) {
                    $locationCreateStruct = $this->locationService->newLocationCreateStruct($newLocation->id);
                    $this->locationService->createLocation($contentInfo, $locationCreateStruct);

                    $this->notificationHandler->success(
                        $this->translator->trans(
                            /** @Desc("Location '%name%' created.") */
                            'location.create.success',
                            ['%name%' => $newLocation->getContentInfo()->name],
                            'location'
                        )
                    );
                }

                return new RedirectResponse($this->generateUrl('_ezpublishLocation', [
                    'locationId' => $contentInfo->mainLocationId,
                    '_fragment' => LocationsTab::URI_FRAGMENT,
                ]));
            });

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

        return $this->redirect($this->generateUrl('_ezpublishLocation', [
            'locationId' => $contentInfo->mainLocationId,
            '_fragment' => LocationsTab::URI_FRAGMENT,
        ]));
    }
public function addAction(Request $request): Response
    {
        $form = $this->formFactory->addLocation(
            new ContentLocationAddData()
        );
        $form->handleRequest($request);

        $contentInfo = $form->getData()->getContentInfo();

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (ContentLocationAddData $data) {
                $contentInfo = $data->getContentInfo();

                foreach ($data->getNewLocations() as $newLocation) {
                    $locationCreateStruct = $this->locationService->newLocationCreateStruct($newLocation->id);
                    $this->locationService->createLocation($contentInfo, $locationCreateStruct);

                    $this->notificationHandler->success(
                        $this->translator->trans(
                            /** @Desc("Location '%name%' created.") */
                            'location.create.success',
                            ['%name%' => $newLocation->getContentInfo()->name],
                            'location'
                        )
                    );
                }

                return new RedirectResponse($this->generateUrl('_ezpublishLocation', [
                    'locationId' => $contentInfo->mainLocationId,
                    '_fragment' => LocationsTab::URI_FRAGMENT,
                ]));
            });

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

        return $this->redirect($this->generateUrl('_ezpublishLocation', [
            'locationId' => $contentInfo->mainLocationId,
            '_fragment' => LocationsTab::URI_FRAGMENT,
        ]));
    }
public function addAction ( Request $ request ) : Response { $ form = $ this -> formFactory -> addLocation ( new ContentLocationAddData ( ) ) ; $ form -> handleRequest ( $ request ) ; $ contentInfo = $ form -> getData ( ) -> getContentInfo ( ) ; if ( $ form -> isSubmitted ( ) ) { $ result = $ this -> submitHandler -> handle ( $ form , function ( ContentLocationAddData $ data ) { $ contentInfo = $ data -> getContentInfo ( ) ; foreach ( $ data -> getNewLocations ( ) as $ newLocation ) { $ locationCreateStruct = $ this -> locationService -> newLocationCreateStruct ( $ newLocation -> id ) ; $ this -> locationService -> createLocation ( $ contentInfo , $ locationCreateStruct ) ; $ this -> notificationHandler -> success ( $ this -> translator -> trans ( /** @Desc("Location '%name%' created.") */ 'location.create.success' , [ '%name%' => $ newLocation -> getContentInfo ( ) -> name ] , 'location' ) ) ; } return new RedirectResponse ( $ this -> generateUrl ( '_ezpublishLocation' , [ 'locationId' => $ contentInfo -> mainLocationId , '_fragment' => LocationsTab :: URI_FRAGMENT , ] ) ) ; } ) ; if ( $ result instanceof Response ) { return $ result ; } } return $ this -> redirect ( $ this -> generateUrl ( '_ezpublishLocation' , [ 'locationId' => $ contentInfo -> mainLocationId , '_fragment' => LocationsTab :: URI_FRAGMENT , ] ) ) ; }
Handles assigning new location to the content item based on submitted form.

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

@return \Symfony\Component\HttpFoundation\Response
Handles assigning new location to the content item based on submitted form .