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); }
/** * Creates a new location for object with id $contentId. * * @param mixed $contentId * * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException * * @return \eZ\Publish\Core\REST\Server\Values\CreatedLocation */ public function createLocation($contentId, Request $request) { $locationCreateStruct = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent())); $contentInfo = $this->contentService->loadContentInfo($contentId); try { $createdLocation = $this->locationService->createLocation($contentInfo, $locationCreateStruct); } catch (InvalidArgumentException $e) { throw new ForbiddenException($e->getMessage()); } return new Values\CreatedLocation(array('restLocation' => new Values\RestLocation($createdLocation, 0))); }
/** * Creates the new $location in the content repository for the given content * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to create this location * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the content is already below the specified parent * or the parent is a sub location of the location of the content * or if set the remoteId exists already * * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo * * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreateStruct * * @return \eZ\Publish\API\Repository\Values\Content\Location the newly created Location * */ public function createLocation(ContentInfo $contentInfo, LocationCreateStruct $locationCreateStruct) { $returnValue = $this->service->createLocation($contentInfo, $locationCreateStruct); $this->signalDispatcher->emit(new CreateLocationSignal(array('contentId' => $contentInfo->id, 'locationId' => $returnValue->id))); return $returnValue; }