getContentLanguageService() публичный Метод

Get service object to perform operations on Content language objects
public getContentLanguageService ( ) : eZ\Publish\API\Repository\LanguageService
Результат eZ\Publish\API\Repository\LanguageService
Пример #1
0
 /**
  * Updates the metadata.
  *
  * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists
  *
  * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
  * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes
  */
 public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct)
 {
     $propertyCount = 0;
     foreach ($contentMetadataUpdateStruct as $propertyName => $propertyValue) {
         if (isset($contentMetadataUpdateStruct->{$propertyName})) {
             $propertyCount += 1;
         }
     }
     if ($propertyCount === 0) {
         throw new InvalidArgumentException('$contentMetadataUpdateStruct', 'At least one property must be set');
     }
     $loadedContentInfo = $this->loadContentInfo($contentInfo->id);
     if (!$this->repository->canUser('content', 'edit', $loadedContentInfo)) {
         throw new UnauthorizedException('content', 'edit', array('contentId' => $loadedContentInfo->id));
     }
     if (isset($contentMetadataUpdateStruct->remoteId)) {
         try {
             $existingContentInfo = $this->loadContentInfoByRemoteId($contentMetadataUpdateStruct->remoteId);
             if ($existingContentInfo->id !== $loadedContentInfo->id) {
                 throw new InvalidArgumentException('$contentMetadataUpdateStruct', "Another content with remoteId '{$contentMetadataUpdateStruct->remoteId}' exists");
             }
         } catch (APINotFoundException $e) {
             // Do nothing
         }
     }
     $this->repository->beginTransaction();
     try {
         if ($propertyCount > 1 || !isset($contentMetadataUpdateStruct->mainLocationId)) {
             $this->persistenceHandler->contentHandler()->updateMetadata($loadedContentInfo->id, new SPIMetadataUpdateStruct(array('ownerId' => $contentMetadataUpdateStruct->ownerId, 'publicationDate' => isset($contentMetadataUpdateStruct->publishedDate) ? $contentMetadataUpdateStruct->publishedDate->getTimestamp() : null, 'modificationDate' => isset($contentMetadataUpdateStruct->modificationDate) ? $contentMetadataUpdateStruct->modificationDate->getTimestamp() : null, 'mainLanguageId' => isset($contentMetadataUpdateStruct->mainLanguageCode) ? $this->repository->getContentLanguageService()->loadLanguage($contentMetadataUpdateStruct->mainLanguageCode)->id : null, 'alwaysAvailable' => $contentMetadataUpdateStruct->alwaysAvailable, 'remoteId' => $contentMetadataUpdateStruct->remoteId)));
         }
         // Change main location
         if (isset($contentMetadataUpdateStruct->mainLocationId) && $loadedContentInfo->mainLocationId !== $contentMetadataUpdateStruct->mainLocationId) {
             $this->persistenceHandler->locationHandler()->changeMainLocation($loadedContentInfo->id, $contentMetadataUpdateStruct->mainLocationId);
         }
         // Republish URL aliases to update always-available flag
         if (isset($contentMetadataUpdateStruct->alwaysAvailable) && $loadedContentInfo->alwaysAvailable !== $contentMetadataUpdateStruct->alwaysAvailable) {
             $content = $this->loadContent($loadedContentInfo->id);
             $this->publishUrlAliasesForContent($content, false);
         }
         $this->repository->commit();
     } catch (Exception $e) {
         $this->repository->rollback();
         throw $e;
     }
     return isset($content) ? $content : $this->loadContent($loadedContentInfo->id);
 }