protected function getSelectionChoices()
 {
     $choices = [];
     foreach ($this->sectionService->loadSections() as $section) {
         $choices[$section->id] = $section->name;
     }
     return $choices;
 }
 /**
  * Parses input structure to a SectionIdentifier Criterion object.
  *
  * @param array $data
  * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
  *
  * @throws \eZ\Publish\Core\REST\Common\Exceptions\Parser
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Query\Criterion\SectionId
  */
 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
 {
     if (!array_key_exists('SectionIdentifierCriterion', $data)) {
         throw new Exceptions\Parser('Invalid <SectionIdentifierCriterion> format');
     }
     $section = $this->sectionService->loadSectionByIdentifier($data['SectionIdentifierCriterion']);
     return new SectionIdCriterion($section->id);
 }
 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']);
 }
 public function testProcessUpdate()
 {
     $existingSection = new Section();
     $updatedSection = new Section();
     $data = new SectionUpdateData(['section' => $existingSection]);
     $event = new FormActionEvent($this->getMock('\\Symfony\\Component\\Form\\FormInterface'), $data, 'foo');
     $this->sectionService->expects($this->once())->method('updateSection')->with($existingSection, $data)->willReturn($updatedSection);
     $this->processor->processUpdate($event);
     self::assertSame($updatedSection, $data->section);
 }
 public function processUpdate(FormActionEvent $event)
 {
     /** @var \EzSystems\RepositoryForms\Data\Section\SectionUpdateData|\EzSystems\RepositoryForms\Data\Section\SectionCreateData $sectionData */
     $sectionData = $event->getData();
     if ($sectionData->isNew()) {
         $section = $this->sectionService->createSection($sectionData);
     } else {
         $section = $this->sectionService->updateSection($sectionData->section, $sectionData);
     }
     $sectionData->setSection($section);
 }
 /**
  * Checks if the passed value is valid.
  *
  * @param SectionUpdateData $value The value that should be validated
  * @param Constraint|UniqueFieldDefinitionIdentifier $constraint The constraint for the validation
  *
  * @api
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$value instanceof SectionUpdateData) {
         return;
     }
     try {
         $section = $this->sectionService->loadSectionByIdentifier($value->identifier);
         if ($section->id == $value->getId()) {
             return;
         }
         $this->context->buildViolation($constraint->message)->atPath('identifier')->setParameter('%identifier%', $value->identifier)->addViolation();
     } catch (NotFoundException $e) {
         // Do nothing
     }
 }
Пример #7
0
 /**
  * Parse input structure
  *
  * @param array $data
  * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
  *
  * @return \eZ\Publish\API\Repository\Values\Content\SectionCreateStruct
  */
 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
 {
     $sectionCreate = $this->sectionService->newSectionCreateStruct();
     //@todo XSD says that name is not mandatory? Does that make sense?
     if (!array_key_exists('name', $data)) {
         throw new Exceptions\Parser("Missing 'name' attribute for SectionInput.");
     }
     $sectionCreate->name = $data['name'];
     //@todo XSD says that identifier is not mandatory? Does that make sense?
     if (!array_key_exists('identifier', $data)) {
         throw new Exceptions\Parser("Missing 'identifier' attribute for SectionInput.");
     }
     $sectionCreate->identifier = $data['identifier'];
     return $sectionCreate;
 }
Пример #8
0
 /**
  * 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()));
 }
Пример #9
0
 /**
  * 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]);
 }
Пример #10
0
 /**
  * Instantiates a new SectionUpdateStruct.
  *
  * @return \eZ\Publish\API\Repository\Values\Content\SectionUpdateStruct
  */
 public function newSectionUpdateStruct()
 {
     return $this->service->newSectionUpdateStruct();
 }
Пример #11
0
 /**
  * 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();
 }
Пример #12
0
 /**
  * Lets you select a section which will be used as limitation when assigning the role.
  *
  * @param Request $request
  * @param int $roleId Role ID
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function assignRoleBySectionLimitationAction(Request $request, $roleId)
 {
     return $this->render('eZPlatformUIBundle:Role:assign_role_by_section.html.twig', ['role' => $this->roleService->loadRole($roleId), 'sections' => $this->sectionService->loadSections(), 'can_assign' => $this->isGranted(new Attribute('role', 'assign'))]);
 }