/** * @param FluidView $view * @return void */ public function initializeView(FluidView $view) { $assets = $this->tsValue('assets'); $processedAssets = array(); /** @var Asset $asset */ if (is_array($assets)) { foreach ($assets as $asset) { if ($asset->getResource() === null) { if ($asset instanceof Image) { $processedAssets[] = $this->imageRepository->findByIdentifier($asset->getIdentifier()); } elseif ($asset instanceof Asset) { $processedAssets[] = $this->assetRepository->findByIdentifier($asset->getIdentifier()); } } else { $processedAssets[] = $asset; } } } $view->assign('assets', $processedAssets); }
/** * @param NodeInterface $node * @param Image $newImage * @param string $title * @param string|array $tagLabel * @param string $propertyName * @param boolean $removePreviousProfileImage * @return NodeInterface */ public function setImageToNode(NodeInterface $node, Image $newImage, $title, $tagLabel = NULL, $propertyName = 'image', $removePreviousProfileImage = FALSE) { $newImage->setTitle($title); if ($tagLabel !== NULL) { if (is_array($tagLabel) && !is_string($tagLabel)) { if ($removePreviousProfileImage === TRUE) { $this->removePreviousProfilePictureBasedOnTags($title, $tagLabel); } foreach ($tagLabel as $key => $label) { $tag = $this->tagRepository->findOneByLabel($label); if (!$tag instanceof Tag) { $tag = new Tag($label); $this->tagRepository->add($tag); } $newImage->addTag($tag); } } elseif (is_string($tagLabel) && !is_array($tagLabel)) { $tag = $this->tagRepository->findOneByLabel($tagLabel); if (!$tag instanceof Tag) { $tag = new Tag($tagLabel); $this->tagRepository->add($tag); } $newImage->addTag($tag); } } /** @var Image $image */ $image = $this->imageRepository->findByIdentifier($newImage->getIdentifier()); if ($image !== NULL) { try { $this->imageRepository->update($image); $node->setProperty($propertyName, $image); } catch (\Exception $exception) { // Image repository might give back an image while not stored for some reason. If so, catch that error and store it anyway $image->setTitle($title); $this->imageRepository->add($image); $node->setProperty($propertyName, $image); $this->systemLogger->log('Image with identifier ' . $image->getIdentifier() . ' stored while preceding an error that is not stored yet fetched using ImageRepository', LOG_CRIT); } } else { $this->imageRepository->add($newImage); $node->setProperty($propertyName, $newImage); } return $node; }
/** * Converts the given $objectXml to an ImageVariant instance and returns it * * @param \SimpleXMLElement $objectXml * @param string $className the concrete class name of the ImageVariant to create (ImageVariant or a subclass) * @return ImageVariant * @throws NeosException */ protected function importImageVariant(\SimpleXMLElement $objectXml, $className) { $processingInstructions = unserialize(trim((string) $objectXml->processingInstructions)); if (isset($objectXml->originalImage['__identifier'])) { $image = $this->imageRepository->findByIdentifier((string) $objectXml->originalImage['__identifier']); if (is_object($image)) { return $this->objectManager->get($className, $image, $processingInstructions); } } $resourceHash = (string) $objectXml->originalImage->resource->hash; $resourceData = trim((string) $objectXml->originalImage->resource->content); if ((string) $objectXml->originalImage->resource['__identifier'] !== '') { $resource = $this->persistenceManager->getObjectByIdentifier((string) $objectXml->originalImage->resource['__identifier'], 'TYPO3\\Flow\\Resource\\Resource'); } if (!isset($resource) || $resource === null) { $resource = $this->importResource((string) $objectXml->originalImage->resource->filename, $resourceHash !== '' ? $resourceHash : null, !empty($resourceData) ? $resourceData : null, (string) $objectXml->originalImage->resource['__identifier'] !== '' ? (string) $objectXml->originalImage->resource['__identifier'] : null); } $image = new Image($resource); if ((string) $objectXml->originalImage['__identifier'] !== '') { ObjectAccess::setProperty($image, 'Persistence_Object_Identifier', (string) $objectXml->originalImage['__identifier'], true); } $this->imageRepository->add($image); return $this->objectManager->get($className, $image, $processingInstructions); }