public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('sectionId', 'hidden', ['constraints' => new Callback(function ($sectionId, ExecutionContextInterface $context) { $contentCount = $this->sectionService->countAssignedContents($this->sectionService->loadSection($sectionId)); if ($contentCount > 0) { $context->buildViolation('section.error.cannot_delete_with_assigned_content')->addViolation(); } })])->add('delete', 'submit', ['label' => 'section.form.delete']); }
/** * Updates a user * * @param $userId * * @return \eZ\Publish\Core\REST\Server\Values\RestUser */ public function updateUser($userId) { $user = $this->userService->loadUser($userId); $updateStruct = $this->inputDispatcher->parse(new Message(array('Content-Type' => $this->request->headers->get('Content-Type'), 'Url' => $this->request->getPathInfo()), $this->request->getContent())); if ($updateStruct->sectionId !== null) { $section = $this->sectionService->loadSection($updateStruct->sectionId); $this->sectionService->assignSection($user->getVersionInfo()->getContentInfo(), $section); } $updatedUser = $this->userService->updateUser($user, $updateStruct->userUpdateStruct); $updatedContentInfo = $updatedUser->getVersionInfo()->getContentInfo(); $mainLocation = $this->locationService->loadLocation($updatedContentInfo->mainLocationId); $contentType = $this->contentTypeService->loadContentType($updatedContentInfo->contentTypeId); return new Values\RestUser($updatedUser, $contentType, $updatedContentInfo, $mainLocation, $this->contentService->loadRelations($updatedUser->getVersionInfo())); }
/** * Displays the edit form and processes it once submitted. * * @param \Symfony\Component\HttpFoundation\Request $request * @param mixed $sectionId * * @return \Symfony\Component\HttpFoundation\Response */ public function editAction(Request $request, $sectionId = null) { $section = $sectionId ? $this->sectionService->loadSection($sectionId) : new Section(['identifier' => '__new__' . md5(microtime(true)), 'name' => 'New section']); $sectionData = (new SectionMapper())->mapToFormData($section); $actionUrl = $this->generateUrl('admin_sectionedit', ['sectionId' => $sectionId]); $form = $this->createForm(new SectionType(), $sectionData); $form->handleRequest($request); if ($form->isValid()) { $this->actionDispatcher->dispatchFormAction($form, $sectionData, $form->getClickedButton() ? $form->getClickedButton()->getName() : null); if ($response = $this->actionDispatcher->getResponse()) { return $response; } return $this->redirectAfterFormPost($actionUrl); } return $this->render('eZPlatformUIBundle:Section:edit.html.twig', ['form' => $form->createView(), 'actionUrl' => $actionUrl, 'section' => $sectionData]); }
/** * Loads a Section from its id ($sectionId). * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if section could not be found * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to read a section * * @param mixed $sectionId * * @return \eZ\Publish\API\Repository\Values\Content\Section */ public function loadSection($sectionId) { return $this->service->loadSection($sectionId); }
/** * Delete a section by ID. * * @param $sectionId * * @return \eZ\Publish\Core\REST\Server\Values\NoContent */ public function deleteSection($sectionId) { $this->sectionService->deleteSection($this->sectionService->loadSection($sectionId)); return new NoContent(); }