/** * Set the node title for the newly created Document node * * @param NodeInterface $node The newly created node * @param array $data incoming data from the creationDialog * @return void */ public function handle(NodeInterface $node, array $data) { if (isset($data['title']) && $node->getNodeType()->isOfType('TYPO3.Neos:Document')) { $node->setProperty('title', $data['title']); $node->setProperty('uriPathSegment', NodeUtility::renderValidNodeName($data['title'])); } }
public function setUp() { parent::setUp(); $this->workspaceRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository'); $liveWorkspace = new Workspace('live'); $this->workspaceRepository->add($liveWorkspace); $this->nodeTypeManager = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager'); $this->contextFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface'); $this->context = $this->contextFactory->create(['workspaceName' => 'live', 'dimensions' => ['language' => ['en_US']], 'targetDimensions' => ['language' => 'en_US']]); $rootNode = $this->context->getRootNode(); $this->siteNode = $rootNode->createNode('welcome', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page')); $this->siteNode->setProperty('title', 'welcome'); $this->nodeDataRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository'); $this->nodeIndexCommandController = $this->objectManager->get('Flowpack\\ElasticSearch\\ContentRepositoryAdaptor\\Command\\NodeIndexCommandController'); $this->createNodesForNodeSearchTest(); }
/** * Fetch thumb url from Vimeo API * * @param NodeInterface $node * @return void */ public function fetchVimeoThumb(NodeInterface $node) { $fullVideo = $node->getProperty('fullVideo'); $fullVideoThumb = $node->getProperty('fullVideoThumb'); if ($fullVideo && !$fullVideoThumb) { $url = 'https://vimeo.com/api/oembed.json?url=http%3A//vimeo.com/' . $fullVideo; $content = file_get_contents($url); $json = json_decode($content, true); $node->setProperty('fullVideoThumb', $json['thumbnail_url']); } else { if (!$fullVideo && $fullVideoThumb) { // Clear thumb, if Vimeo video is gone. Useful for reloading thumb. $node->setProperty('fullVideoThumb', ''); } } }
public function setUp() { parent::setUp(); $this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class); $liveWorkspace = new Workspace('live'); $this->workspaceRepository->add($liveWorkspace); $this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class); $this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class); $this->context = $this->contextFactory->create(['workspaceName' => 'live', 'dimensions' => ['language' => ['en_US']], 'targetDimensions' => ['language' => 'en_US']]); $rootNode = $this->context->getRootNode(); $this->siteNode = $rootNode->createNode('welcome', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page')); $this->siteNode->setProperty('title', 'welcome'); $this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class); $this->nodeIndexCommandController = $this->objectManager->get(NodeIndexCommandController::class); $this->createNodesForNodeSearchTest(); }
/** * Sets default node property values on the given node. * * @param NodeInterface $node * @return void */ public function setDefaultValues(NodeInterface $node) { $nodeType = $node->getNodeType(); foreach ($nodeType->getDefaultValuesForProperties() as $propertyName => $defaultValue) { if (trim($node->getProperty($propertyName)) === '') { $node->setProperty($propertyName, $defaultValue); } } }
/** * Sets the best possible uriPathSegment for the given Node. * Will use an already set uriPathSegment or alternatively the node name as base, * then checks if the uriPathSegment already exists on the same level and appends a counter until a unique path segment was found. * * @param NodeInterface $node * @return void */ public static function setUniqueUriPathSegment(NodeInterface $node) { if ($node->getNodeType()->isOfType('TYPO3.Neos:Document')) { $q = new FlowQuery(array($node)); $q = $q->context(array('invisibleContentShown' => true, 'removedContentShown' => true, 'inaccessibleContentShown' => true)); $possibleUriPathSegment = $initialUriPathSegment = !$node->hasProperty('uriPathSegment') ? $node->getName() : $node->getProperty('uriPathSegment'); $i = 1; while ($q->siblings('[instanceof TYPO3.Neos:Document][uriPathSegment="' . $possibleUriPathSegment . '"]')->count() > 0) { $possibleUriPathSegment = $initialUriPathSegment . '-' . $i++; } $node->setProperty('uriPathSegment', $possibleUriPathSegment); } }
/** * Increase read counter of the node by one * * @param NodeInterface $node Node to increase the read counter for * * @throws BadRequestException * @return mixed[] */ public function trackAction(NodeInterface $node) { // we can only count pages that include the mixin if ($node->getNodeType()->isOfType('Futjikato.ReadCounter:CounterMixin')) { $node->setProperty('readcounter', $node->getProperty('readcounter') + 1); /** * Action changes data but is accessible via GET. this issues a error if we do not manually * persists the object in the persistence manager */ $this->persistenceManager->persistAll(); // by default the flow JSON view uses the 'value' variable $this->view->assign('value', array('readcounter' => $node->getProperty('readcounter'))); } else { throw new BadRequestException('Node does not contain Futjikato.ReadCounter:CounterMixin.'); } }
/** * Add the new property with the given value on the given node. * * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $node * @return void */ public function execute(\TYPO3\TYPO3CR\Domain\Model\NodeInterface $node) { $node->setProperty($this->newPropertyName, $this->value); }
/** * Sets the given $nodePropertyXml on the $node instance * * @param \SimpleXMLElement $nodePropertyXml * @param NodeInterface $node * @return void */ protected function importNodeProperty(\SimpleXMLElement $nodePropertyXml, NodeInterface $node) { if (!isset($nodePropertyXml['__type'])) { $node->setProperty($nodePropertyXml->getName(), (string) $nodePropertyXml); return; } switch ($nodePropertyXml['__type']) { case 'boolean': $node->setProperty($nodePropertyXml->getName(), (string) $nodePropertyXml === '1'); break; case 'reference': $targetIdentifier = (string) $nodePropertyXml->node['identifier'] === '' ? null : (string) $nodePropertyXml->node['identifier']; $node->setProperty($nodePropertyXml->getName(), $targetIdentifier); break; case 'references': $referencedNodeIdentifiers = array(); foreach ($nodePropertyXml->node as $referenceNodeXml) { if ((string) $referenceNodeXml['identifier'] !== '') { $referencedNodeIdentifiers[] = (string) $referenceNodeXml['identifier']; } } $node->setProperty($nodePropertyXml->getName(), $referencedNodeIdentifiers); break; case 'array': $entries = array(); foreach ($nodePropertyXml->children() as $childNodeXml) { $entry = null; if (!isset($childNodeXml['__classname']) || !in_array($childNodeXml['__classname'], array('TYPO3\\Media\\Domain\\Model\\Image', 'TYPO3\\Media\\Domain\\Model\\Asset'))) { // Only arrays of asset objects are supported now continue; } $entryClassName = (string) $childNodeXml['__classname']; if (isset($childNodeXml['__identifier'])) { if ($entryClassName === 'TYPO3\\Media\\Domain\\Model\\Image') { $entry = $this->imageRepository->findByIdentifier((string) $childNodeXml['__identifier']); } else { $entry = $this->assetRepository->findByIdentifier((string) $childNodeXml['__identifier']); } } if ($entry === null) { $resourceXml = $childNodeXml->xpath('resource'); $resourceHash = $resourceXml[0]->xpath('hash'); $content = $resourceXml[0]->xpath('content'); $filename = $resourceXml[0]->xpath('filename'); $resource = $this->importResource(!empty($filename) ? (string) $filename[0] : null, !empty($resourceHash) ? (string) $resourceHash[0] : null, !empty($content) ? (string) $content[0] : null, isset($resourceXml[0]['__identifier']) ? (string) $resourceXml[0]['__identifier'] : null); $entry = new $entryClassName($resource); if (isset($childNodeXml['__identifier'])) { ObjectAccess::setProperty($entry, 'Persistence_Object_Identifier', (string) $childNodeXml['__identifier'], true); } } $propertiesXml = $childNodeXml->xpath('properties/*'); foreach ($propertiesXml as $propertyXml) { if (!isset($propertyXml['__type'])) { ObjectAccess::setProperty($entry, $propertyXml->getName(), (string) $propertyXml); continue; } switch ($propertyXml['__type']) { case 'boolean': ObjectAccess::setProperty($entry, $propertyXml->getName(), (bool) $propertyXml); break; case 'string': ObjectAccess::setProperty($entry, $propertyXml->getName(), (string) $propertyXml); break; case 'object': ObjectAccess::setProperty($entry, $propertyXml->getName(), $this->xmlToObject($propertyXml)); } } /** * During the persist Doctrine calls the serialize() method on the asset for the ObjectArray * object, during this serialize the resource property gets lost. * The AssetList node type has a custom implementation to work around this bug. * @see NEOS-121 */ $repositoryAction = $this->persistenceManager->isNewObject($entry) ? 'add' : 'update'; if ($entry instanceof Image) { $this->imageRepository->{$repositoryAction}($entry); } else { $this->assetRepository->{$repositoryAction}($entry); } $entries[] = $entry; } $node->setProperty($nodePropertyXml->getName(), $entries); break; case 'object': $node->setProperty($nodePropertyXml->getName(), $this->xmlToObject($nodePropertyXml)); break; } }
/** * @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; }
/** * Renames the configured property to the new name. * * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $node * @return void */ public function execute(\TYPO3\TYPO3CR\Domain\Model\NodeInterface $node) { $node->setProperty($this->newPropertyName, $node->getProperty($this->oldPropertyName)); $node->removeProperty($this->oldPropertyName); }
/** * Traverses through the tree starting at the given root node and sets the uriPathSegment property derived from * the node label. * * @param NodeInterface $node The node where the traversal starts * @param boolean $dryRun * @return void */ protected function generateUriPathSegmentsForNode(NodeInterface $node, $dryRun) { if ((string) $node->getProperty('uriPathSegment') === '') { $name = $node->getLabel() ?: $node->getName(); $uriPathSegment = Utility::renderValidNodeName($name); if ($dryRun === FALSE) { $node->setProperty('uriPathSegment', $uriPathSegment); $this->output->outputLine('Added missing URI path segment for "%s" (%s) => %s', array($node->getPath(), $name, $uriPathSegment)); } else { $this->output->outputLine('Found missing URI path segment for "%s" (%s) => %s', array($node->getPath(), $name, $uriPathSegment)); } } foreach ($node->getChildNodes('TYPO3.Neos:Document') as $childNode) { $this->generateUriPathSegmentsForNode($childNode, $dryRun); } }
/** * Strips tags on the value of the property to work on. * * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $node * @return void */ public function execute(\TYPO3\TYPO3CR\Domain\Model\NodeInterface $node) { $node->setProperty($this->propertyName, strip_tags($node->getProperty($this->propertyName))); }
/** * Set node properties * * @param NodeInterface $node * @param array $properties * @param array $args */ protected function setNodeProperties(NodeInterface $node, array $properties, array $args = []) { foreach ($properties as $property => $value) { $value = count($args) && is_string($value) ? vsprintf($value, $args) : $value; $node->setProperty($property, $value); } }
/** * Change the property on the given node. * * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $node * @return void */ public function execute(\TYPO3\TYPO3CR\Domain\Model\NodeInterface $node) { $currentPropertyValue = $node->getProperty($this->propertyName); $newValueWithReplacedCurrentValue = str_replace($this->currentValuePlaceholder, $currentPropertyValue, $this->newValue); $node->setProperty($this->propertyName, $newValueWithReplacedCurrentValue); }