/** * 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"]); } } } } }
/** * 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']); } } } }