Exemplo n.º 1
0
 /**
  * Parse input structure.
  *
  * @param array $data
  * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
  *
  * @return \Netgen\TagsBundle\API\Repository\Values\Tags\TagCreateStruct
  */
 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
 {
     if (!array_key_exists('ParentTag', $data) || !is_array($data['ParentTag'])) {
         throw new Exceptions\Parser("Missing or invalid 'ParentTag' element for TagCreate.");
     }
     if (!array_key_exists('_href', $data['ParentTag'])) {
         throw new Exceptions\Parser("Missing '_href' attribute for ParentTag element in TagCreate.");
     }
     if (!array_key_exists('mainLanguageCode', $data)) {
         throw new Exceptions\Parser("Missing 'mainLanguageCode' element for TagCreate.");
     }
     $tagHrefParts = explode('/', $this->requestParser->parseHref($data['ParentTag']['_href'], 'tagPath'));
     $tagCreateStruct = $this->tagsService->newTagCreateStruct(array_pop($tagHrefParts), $data['mainLanguageCode']);
     if (array_key_exists('remoteId', $data)) {
         $tagCreateStruct->remoteId = $data['remoteId'];
     }
     if (array_key_exists('alwaysAvailable', $data)) {
         $tagCreateStruct->alwaysAvailable = $this->parserTools->parseBooleanValue($data['alwaysAvailable']);
     }
     if (array_key_exists('names', $data)) {
         if (!is_array($data['names']) || !array_key_exists('value', $data['names']) || !is_array($data['names']['value'])) {
             throw new Exceptions\Parser("Invalid 'names' element for TagCreate.");
         }
         $keywords = $this->parserTools->parseTranslatableList($data['names']);
         foreach ($keywords as $languageCode => $keyword) {
             $tagCreateStruct->setKeyword($keyword, $languageCode);
         }
     }
     return $tagCreateStruct;
 }
Exemplo n.º 2
0
 /**
  * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
  *
  * @covers \Netgen\TagsBundle\Core\Repository\TagsService::createTag
  * @depends testNewTagCreateStruct
  */
 public function testCreateTagThrowsUnauthorizedException()
 {
     $this->repository->setCurrentUser($this->getStubbedUser(10));
     $createStruct = $this->tagsService->newTagCreateStruct(40, 'eng-GB');
     $createStruct->remoteId = 'New remote ID';
     $this->tagsService->createTag($createStruct);
 }
Exemplo n.º 3
0
 /**
  * Instantiates a new tag create struct.
  *
  * @param mixed $parentTagId
  * @param string $mainLanguageCode
  *
  * @return \Netgen\TagsBundle\API\Repository\Values\Tags\TagCreateStruct
  */
 public function newTagCreateStruct($parentTagId, $mainLanguageCode)
 {
     return $this->service->newTagCreateStruct($parentTagId, $mainLanguageCode);
 }