eZ\Publish\Core\Repository\Helper\DomainMapper::buildSPILocationCreateStruct PHP Method

buildSPILocationCreateStruct() public method

Creates an array of SPI location create structs from given array of API location create structs.
public buildSPILocationCreateStruct ( eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreateStruct, eZ\Publish\API\Repository\Values\Content\Location $parentLocation, mixed $mainLocation, mixed $contentId, mixed $contentVersionNo ) : eZ\Publish\SPI\Persistence\Content\Location\CreateStruct
$locationCreateStruct eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
$parentLocation eZ\Publish\API\Repository\Values\Content\Location
$mainLocation mixed
$contentId mixed
$contentVersionNo mixed
return eZ\Publish\SPI\Persistence\Content\Location\CreateStruct
    public function buildSPILocationCreateStruct($locationCreateStruct, APILocation $parentLocation, $mainLocation, $contentId, $contentVersionNo)
    {
        if ($locationCreateStruct->priority !== null && !is_int($locationCreateStruct->priority)) {
            throw new InvalidArgumentValue('priority', $locationCreateStruct->priority, 'LocationCreateStruct');
        }
        if (!is_bool($locationCreateStruct->hidden)) {
            throw new InvalidArgumentValue('hidden', $locationCreateStruct->hidden, 'LocationCreateStruct');
        }
        if ($locationCreateStruct->remoteId !== null && (!is_string($locationCreateStruct->remoteId) || empty($locationCreateStruct->remoteId))) {
            throw new InvalidArgumentValue('remoteId', $locationCreateStruct->remoteId, 'LocationCreateStruct');
        }
        if ($locationCreateStruct->sortField !== null && !$this->isValidLocationSortField($locationCreateStruct->sortField)) {
            throw new InvalidArgumentValue('sortField', $locationCreateStruct->sortField, 'LocationCreateStruct');
        }
        if ($locationCreateStruct->sortOrder !== null && !$this->isValidLocationSortOrder($locationCreateStruct->sortOrder)) {
            throw new InvalidArgumentValue('sortOrder', $locationCreateStruct->sortOrder, 'LocationCreateStruct');
        }
        $remoteId = $locationCreateStruct->remoteId;
        if (null === $remoteId) {
            $remoteId = $this->getUniqueHash($locationCreateStruct);
        } else {
            try {
                $this->locationHandler->loadByRemoteId($remoteId);
                throw new InvalidArgumentException('$locationCreateStructs', "Another Location with remoteId '{$remoteId}' exists");
            } catch (NotFoundException $e) {
                // Do nothing
            }
        }
        return new SPILocationCreateStruct(array('priority' => $locationCreateStruct->priority, 'hidden' => $locationCreateStruct->hidden, 'invisible' => $locationCreateStruct->hidden === true || $parentLocation->invisible, 'remoteId' => $remoteId, 'contentId' => $contentId, 'contentVersion' => $contentVersionNo, 'pathIdentificationString' => null, 'mainLocationId' => $mainLocation, 'sortField' => $locationCreateStruct->sortField !== null ? $locationCreateStruct->sortField : Location::SORT_FIELD_NAME, 'sortOrder' => $locationCreateStruct->sortOrder !== null ? $locationCreateStruct->sortOrder : Location::SORT_ORDER_ASC, 'parentId' => $locationCreateStruct->parentLocationId));
    }

Usage Example

 /**
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
  *
  * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct[]
  */
 protected function buildSPILocationCreateStructs(array $locationCreateStructs)
 {
     $spiLocationCreateStructs = array();
     $parentLocationIdSet = array();
     $mainLocation = true;
     foreach ($locationCreateStructs as $locationCreateStruct) {
         if (isset($parentLocationIdSet[$locationCreateStruct->parentLocationId])) {
             throw new InvalidArgumentException('$locationCreateStructs', "Multiple LocationCreateStructs with the same parent Location '{$locationCreateStruct->parentLocationId}' are given");
         }
         $parentLocationIdSet[$locationCreateStruct->parentLocationId] = true;
         $parentLocation = $this->repository->getLocationService()->loadLocation($locationCreateStruct->parentLocationId);
         $spiLocationCreateStructs[] = $this->domainMapper->buildSPILocationCreateStruct($locationCreateStruct, $parentLocation, $mainLocation, null, null);
         // First Location in the list will be created as main Location
         $mainLocation = false;
     }
     return $spiLocationCreateStructs;
 }
All Usage Examples Of eZ\Publish\Core\Repository\Helper\DomainMapper::buildSPILocationCreateStruct