/** * Parse input structure * * @param array $data * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher * * @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct */ public function parse(array $data, ParsingDispatcher $parsingDispatcher) { if (!array_key_exists('ParentLocation', $data) || !is_array($data['ParentLocation'])) { throw new Exceptions\Parser("Missing or invalid 'ParentLocation' element for LocationCreate."); } if (!array_key_exists('_href', $data['ParentLocation'])) { throw new Exceptions\Parser("Missing '_href' attribute for ParentLocation element in LocationCreate."); } $locationHrefParts = explode('/', $this->requestParser->parseHref($data['ParentLocation']['_href'], 'locationPath')); $locationCreateStruct = $this->locationService->newLocationCreateStruct(array_pop($locationHrefParts)); if (array_key_exists('priority', $data)) { $locationCreateStruct->priority = (int) $data['priority']; } if (array_key_exists('hidden', $data)) { $locationCreateStruct->hidden = $this->parserTools->parseBooleanValue($data['hidden']); } if (array_key_exists('remoteId', $data)) { $locationCreateStruct->remoteId = $data['remoteId']; } if (!array_key_exists('sortField', $data)) { throw new Exceptions\Parser("Missing 'sortField' element for LocationCreate."); } $locationCreateStruct->sortField = $this->parserTools->parseDefaultSortField($data['sortField']); if (!array_key_exists('sortOrder', $data)) { throw new Exceptions\Parser("Missing 'sortOrder' element for LocationCreate."); } $locationCreateStruct->sortOrder = $this->parserTools->parseDefaultSortOrder($data['sortOrder']); return $locationCreateStruct; }
public function setPostCategories($postId, Request $request) { $this->login($request->request->get('username'), $request->request->get('password')); // @todo Replace categories instead of adding $contentInfo = $this->contentService->loadContentInfo($postId); foreach ($request->request->get('categories') as $category) { $this->locationService->createLocation($contentInfo, $this->locationService->newLocationCreateStruct($category['categoryId'])); } return new Response(true); }
/** * Displays and processes a content creation form. Showing the form does not create a draft in the repository. * * @param int $contentTypeIdentifier ContentType id to create * @param string $language Language code to create the content in (eng-GB, ger-DE, ...)) * @param int $parentLocationId Location the content should be a child of * @param \Symfony\Component\HttpFoundation\Request $request * * @return \Symfony\Component\HttpFoundation\Response */ public function createWithoutDraftAction($contentTypeIdentifier, $language, $parentLocationId, Request $request) { $contentType = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); $data = (new ContentCreateMapper())->mapToFormData($contentType, ['mainLanguageCode' => $language, 'parentLocation' => $this->locationService->newLocationCreateStruct($parentLocationId)]); $form = $this->createForm(ContentEditType::class, $data, ['languageCode' => $language]); $form->handleRequest($request); if ($form->isValid()) { $this->contentActionDispatcher->dispatchFormAction($form, $data, $form->getClickedButton()->getName()); if ($response = $this->contentActionDispatcher->getResponse()) { return $response; } } return $this->render('EzSystemsRepositoryFormsBundle:Content:content_edit.html.twig', ['form' => $form->createView(), 'languageCode' => $language, 'pagelayout' => $this->pagelayout]); }
/** * Creates and prepares location create structure. * * @param array $data * @param int $defaultLocationId * @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct */ private function getLocationCreateStruct($data, $defaultLocationId) { $parentLocationId = $this->getContentDataParentLocationId($data, $defaultLocationId); $locationStruct = $this->locationService->newLocationCreateStruct($parentLocationId); $locationStruct->priority = isset($data['priority']) ? $data['priority'] : 0; return $locationStruct; }
/** * Instantiates a new location create class * * @param mixed $parentLocationId the parent under which the new location should be created * * @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct */ public function newLocationCreateStruct($parentLocationId) { return $this->service->newLocationCreateStruct($parentLocationId); }