eZ\Publish\Core\Repository\Helper\NameSchemaService::resolveUrlAliasSchema PHP Method

resolveUrlAliasSchema() public method

Convenience method for resolving URL alias schema.
public resolveUrlAliasSchema ( eZ\Publish\API\Repository\Values\Content\Content $content, eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType = null ) : array
$content eZ\Publish\API\Repository\Values\Content\Content
$contentType eZ\Publish\API\Repository\Values\ContentType\ContentType
return array
    public function resolveUrlAliasSchema(Content $content, ContentType $contentType = null)
    {
        if ($contentType === null) {
            $contentType = $this->contentTypeHandler->load($content->contentInfo->contentTypeId);
        }
        return $this->resolve(strlen($contentType->urlAliasSchema) === 0 ? $contentType->nameSchema : $contentType->urlAliasSchema, $contentType, $content->fields, $content->versionInfo->languageCodes);
    }

Usage Example

 /**
  * Recovers the $trashedLocation at its original place if possible.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to recover the trash item at the parent location location
  *
  * If $newParentLocation is provided, $trashedLocation will be restored under it.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\TrashItem $trashItem
  * @param \eZ\Publish\API\Repository\Values\Content\Location $newParentLocation
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Location the newly created or recovered location
  */
 public function recover(APITrashItem $trashItem, Location $newParentLocation = null)
 {
     if (!is_numeric($trashItem->id)) {
         throw new InvalidArgumentValue("id", $trashItem->id, "TrashItem");
     }
     if ($newParentLocation === null && !is_numeric($trashItem->parentLocationId)) {
         throw new InvalidArgumentValue("parentLocationId", $trashItem->parentLocationId, "TrashItem");
     }
     if ($newParentLocation !== null && !is_numeric($newParentLocation->id)) {
         throw new InvalidArgumentValue("parentLocationId", $newParentLocation->id, "Location");
     }
     if ($this->repository->hasAccess('content', 'restore') !== true) {
         throw new UnauthorizedException('content', 'restore');
     }
     $this->repository->beginTransaction();
     try {
         $newParentLocationId = $newParentLocation ? $newParentLocation->id : $trashItem->parentLocationId;
         $newLocationId = $this->persistenceHandler->trashHandler()->recover($trashItem->id, $newParentLocationId);
         $content = $this->repository->getContentService()->loadContent($trashItem->contentId);
         $urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content);
         // Publish URL aliases for recovered location
         foreach ($urlAliasNames as $languageCode => $name) {
             $this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation($newLocationId, $newParentLocationId, $name, $languageCode, $content->contentInfo->alwaysAvailable);
         }
         $this->repository->commit();
     } catch (Exception $e) {
         $this->repository->rollback();
         throw $e;
     }
     return $this->repository->getLocationService()->loadLocation($newLocationId);
 }
All Usage Examples Of eZ\Publish\Core\Repository\Helper\NameSchemaService::resolveUrlAliasSchema