/**
  * Appends destination Content ids of given $fieldValue to the $relation array.
  *
  * If $fieldValue contains Location ids, the will be converted to the Content id that Location encapsulates.
  *
  * @param array $relations
  * @param array $locationIdToContentIdMapping An array with Location Ids as keys and corresponding Content Id as values
  * @param \eZ\Publish\SPI\FieldType\FieldType $fieldType
  * @param \eZ\Publish\Core\FieldType\Value $fieldValue Accepted field value.
  * @param string $fieldDefinitionId
  */
 public function appendFieldRelations(array &$relations, array &$locationIdToContentIdMapping, SPIFieldType $fieldType, BaseValue $fieldValue, $fieldDefinitionId)
 {
     foreach ($fieldType->getRelations($fieldValue) as $relationType => $destinationIds) {
         if ($relationType === Relation::FIELD) {
             if (!isset($relations[$relationType][$fieldDefinitionId])) {
                 $relations[$relationType][$fieldDefinitionId] = array();
             }
             $relations[$relationType][$fieldDefinitionId] += array_flip($destinationIds);
         } elseif ($relationType & (Relation::LINK | Relation::EMBED)) {
             // Using bitwise operators as Legacy Stack stores COMMON, LINK and EMBED relation types
             // in the same entry using bitmask
             if (!isset($relations[$relationType])) {
                 $relations[$relationType] = array();
             }
             if (isset($destinationIds['locationIds'])) {
                 foreach ($destinationIds['locationIds'] as $locationId) {
                     if (!isset($locationIdToContentIdMapping[$locationId])) {
                         $location = $this->persistenceHandler->locationHandler()->load($locationId);
                         $locationIdToContentIdMapping[$locationId] = $location->contentId;
                     }
                     $relations[$relationType][$locationIdToContentIdMapping[$locationId]] = true;
                 }
             }
             if (isset($destinationIds['contentIds'])) {
                 $relations[$relationType] += array_flip($destinationIds['contentIds']);
             }
         }
     }
 }
 /**
  * Appends destination Content ids of given $fieldValue to the $relation array.
  *
  * If $fieldValue contains Location ids, the will be converted to the Content id that Location encapsulates.
  *
  * @param array $relations
  * @param array $locationIdToContentIdMapping An array with Location Ids as keys and corresponding Content Id as values
  * @param \eZ\Publish\SPI\FieldType\FieldType $fieldType
  * @param \eZ\Publish\Core\FieldType\Value $fieldValue Accepted field value.
  * @param string $fieldDefinitionId
  *
  * @return void
  */
 public function appendFieldRelations(array &$relations, array &$locationIdToContentIdMapping, SPIFieldType $fieldType, BaseValue $fieldValue, $fieldDefinitionId)
 {
     foreach ($fieldType->getRelations($fieldValue) as $relationType => $destinationIds) {
         if ($relationType === Relation::FIELD) {
             if (!isset($relations[$relationType][$fieldDefinitionId])) {
                 $relations[$relationType][$fieldDefinitionId] = array();
             }
             $relations[$relationType][$fieldDefinitionId] += array_flip($destinationIds);
         } else {
             if ($relationType & (Relation::LINK | Relation::EMBED)) {
                 if (!isset($relations[$relationType])) {
                     $relations[$relationType] = array();
                 }
                 if (isset($destinationIds["locationIds"])) {
                     foreach ($destinationIds["locationIds"] as $locationId) {
                         if (!isset($locationIdToContentIdMapping[$locationId])) {
                             $location = $this->repository->getLocationService()->loadLocation($locationId);
                             $locationIdToContentIdMapping[$locationId] = $location->contentId;
                         }
                         $relations[$relationType][$locationIdToContentIdMapping[$locationId]] = true;
                     }
                 }
                 if (isset($destinationIds["contentIds"])) {
                     $relations[$relationType] += array_flip($destinationIds["contentIds"]);
                 }
             }
         }
     }
 }
 /**
  * Builds SPIFieldDefinition object using API FieldDefinitionCreateStruct
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException if validator configuration or
  *         field setting do not validate
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct $fieldDefinitionCreateStruct
  * @param \eZ\Publish\SPI\FieldType\FieldType $fieldType
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition
  */
 protected function buildSPIFieldDefinitionCreate(FieldDefinitionCreateStruct $fieldDefinitionCreateStruct, SPIFieldType $fieldType)
 {
     $spiFieldDefinition = new SPIFieldDefinition(array("id" => null, "identifier" => $fieldDefinitionCreateStruct->identifier, "fieldType" => $fieldDefinitionCreateStruct->fieldTypeIdentifier, "name" => $fieldDefinitionCreateStruct->names === null ? array() : $fieldDefinitionCreateStruct->names, "description" => $fieldDefinitionCreateStruct->descriptions === null ? array() : $fieldDefinitionCreateStruct->descriptions, "fieldGroup" => $fieldDefinitionCreateStruct->fieldGroup === null ? "" : $fieldDefinitionCreateStruct->fieldGroup, "position" => (int) $fieldDefinitionCreateStruct->position, "isTranslatable" => $fieldDefinitionCreateStruct->isTranslatable === null ? true : $fieldDefinitionCreateStruct->isTranslatable, "isRequired" => $fieldDefinitionCreateStruct->isRequired === null ? false : $fieldDefinitionCreateStruct->isRequired, "isInfoCollector" => $fieldDefinitionCreateStruct->isInfoCollector === null ? false : $fieldDefinitionCreateStruct->isInfoCollector, "isSearchable" => $fieldDefinitionCreateStruct->isSearchable === null ? $fieldType->isSearchable() : $fieldDefinitionCreateStruct->isSearchable));
     $spiFieldDefinition->fieldTypeConstraints->validators = $fieldDefinitionCreateStruct->validatorConfiguration;
     $spiFieldDefinition->fieldTypeConstraints->fieldSettings = $fieldDefinitionCreateStruct->fieldSettings;
     $spiFieldDefinition->defaultValue = $fieldType->toPersistenceValue($fieldType->acceptValue($fieldDefinitionCreateStruct->defaultValue));
     return $spiFieldDefinition;
 }
Beispiel #4
0
 /**
  * Returns the empty value for the field type that can be processed by the storage engine.
  *
  * @return \eZ\Publish\SPI\Persistence\Content\FieldValue
  */
 public function getEmptyValue()
 {
     return $this->internalFieldType->toPersistenceValue($this->internalFieldType->getEmptyValue());
 }
 /**
  * Builds SPIFieldDefinition object using API FieldDefinitionCreateStruct.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException if validator configuration or
  *         field setting do not validate
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct $fieldDefinitionCreateStruct
  * @param \eZ\Publish\SPI\FieldType\FieldType $fieldType
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition
  */
 public function buildSPIFieldDefinitionCreate(APIFieldDefinitionCreateStruct $fieldDefinitionCreateStruct, SPIFieldType $fieldType)
 {
     $spiFieldDefinition = new SPIFieldDefinition(array('id' => null, 'identifier' => $fieldDefinitionCreateStruct->identifier, 'fieldType' => $fieldDefinitionCreateStruct->fieldTypeIdentifier, 'name' => $fieldDefinitionCreateStruct->names === null ? array() : $fieldDefinitionCreateStruct->names, 'description' => $fieldDefinitionCreateStruct->descriptions === null ? array() : $fieldDefinitionCreateStruct->descriptions, 'fieldGroup' => $fieldDefinitionCreateStruct->fieldGroup === null ? '' : $fieldDefinitionCreateStruct->fieldGroup, 'position' => (int) $fieldDefinitionCreateStruct->position, 'isTranslatable' => $fieldDefinitionCreateStruct->isTranslatable === null ? true : $fieldDefinitionCreateStruct->isTranslatable, 'isRequired' => $fieldDefinitionCreateStruct->isRequired === null ? false : $fieldDefinitionCreateStruct->isRequired, 'isInfoCollector' => $fieldDefinitionCreateStruct->isInfoCollector === null ? false : $fieldDefinitionCreateStruct->isInfoCollector, 'isSearchable' => $fieldDefinitionCreateStruct->isSearchable === null ? $fieldType->isSearchable() : $fieldDefinitionCreateStruct->isSearchable));
     $spiFieldDefinition->fieldTypeConstraints->validators = $fieldDefinitionCreateStruct->validatorConfiguration;
     $spiFieldDefinition->fieldTypeConstraints->fieldSettings = $fieldDefinitionCreateStruct->fieldSettings;
     $spiFieldDefinition->defaultValue = $fieldType->toPersistenceValue($fieldType->acceptValue($fieldDefinitionCreateStruct->defaultValue));
     return $spiFieldDefinition;
 }
 /**
  * Validates FieldDefinitionCreateStruct.
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct $fieldDefinitionCreateStruct
  * @param \eZ\Publish\SPI\FieldType\FieldType $fieldType
  *
  * @return \eZ\Publish\SPI\FieldType\ValidationError[]
  */
 protected function validateFieldDefinitionCreateStruct(FieldDefinitionCreateStruct $fieldDefinitionCreateStruct, SPIFieldType $fieldType)
 {
     $validationErrors = array();
     if ($fieldDefinitionCreateStruct->isSearchable && !$fieldType->isSearchable()) {
         $validationErrors[] = new ValidationError("FieldType '{$fieldDefinitionCreateStruct->fieldTypeIdentifier}' is not searchable");
     }
     return array_merge($validationErrors, $fieldType->validateValidatorConfiguration($fieldDefinitionCreateStruct->validatorConfiguration), $fieldType->validateFieldSettings($fieldDefinitionCreateStruct->fieldSettings));
 }
 /**
  * @param \eZ\Publish\SPI\FieldType\Value $value
  * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition
  * @param string $languageCode
  *
  * @return string
  */
 public function getFieldName(SPIValue $value, FieldDefinition $fieldDefinition, $languageCode)
 {
     return $this->fieldType->getName($value);
 }