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']); }
/** * Counts the contents which $section is assigned to. * * @param \eZ\Publish\API\Repository\Values\Content\Section $section * * @return int * * @deprecated since 6.0 */ public function countAssignedContents(Section $section) { return $this->service->countAssignedContents($section); }
/** * Renders the view of a section. * * @param mixed $sectionId * * @return \Symfony\Component\HttpFoundation\Response */ public function viewAction($sectionId) { $section = $this->sectionService->loadSection($sectionId); $deleteForm = $this->createForm(new SectionDeleteType($this->sectionService), ['sectionId' => $sectionId]); return $this->render('eZPlatformUIBundle:Section:view.html.twig', ['section' => $section, 'deleteForm' => $deleteForm->createView(), 'contentCount' => $this->sectionService->countAssignedContents($section), 'deletable' => !$this->sectionService->isSectionUsed($section), 'canEdit' => $this->isGranted(new Attribute('section', 'edit')), 'canAssign' => $this->isGranted(new Attribute('section', 'assign'))]); }