/** * {@inheritdoc} */ public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey = null) { if ($node->hasProperty($property->getName())) { $value = $node->getPropertyValue($property->getName()); $property->setValue($value); } }
/** * {@inheritdoc} */ public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey) { $values = []; if ($node->hasProperty($property->getName())) { $values = $node->getPropertyValue($property->getName()); } $this->setData($values, $property); }
/** * {@inheritdoc} */ public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey) { $value = $this->defaultValue; if ($node->hasProperty($property->getName())) { $value = $node->getPropertyValue($property->getName()); } $property->setValue($this->decodeValue($value)); return $value; }
/** * {@inheritdoc} */ public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey) { $values = []; if ($node->hasProperty($property->getName())) { $values = $node->getPropertyValue($property->getName()); } $refs = isset($values) ? $values : []; $property->setValue($refs); }
public function testReadPropertyNotExists() { $type = new ContactSelectionContentType($this->template, $this->contactManager->reveal(), $this->accountManager->reveal(), $this->serializer->reveal(), new CustomerIdConverter(), new IndexComparator()); $this->property->getName()->willReturn('test'); $this->node->hasProperty('test')->willReturn(false); $this->node->getPropertyValue(Argument::any(), Argument::any())->shouldNotBeCalled(); $this->property->setValue([])->shouldBeCalled(); $type->read($this->node->reveal(), $this->property->reveal(), $this->webspaceKey, $this->locale, $this->segmentKey); }
/** * {@inheritdoc} */ public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey) { $value = ''; if ($node->hasProperty($property->getName())) { /** @var \DateTime $propertyValue */ $propertyValue = $node->getPropertyValue($property->getName()); $value = $propertyValue->format('Y-m-d'); } $property->setValue($value); return $value; }
/** * {@inheritdoc} */ public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey) { $value = $this->defaultValue; if ($node->hasProperty($property->getName())) { $value = $node->getPropertyValue($property->getName()); } // the RedirectType subscriber sets the internal link as a reference if ($value instanceof NodeInterface) { $value = $value->getIdentifier(); } $property->setValue($value); return $value; }
/** * {@inheritdoc} */ public function resolveMetadataForNode(NodeInterface $node) { if (false === $node->hasProperty('jcr:mixinTypes')) { return; } $mixinTypes = (array) $node->getPropertyValue('jcr:mixinTypes'); foreach ($mixinTypes as $mixinType) { if (true == $this->metadataFactory->hasMetadataForPhpcrType($mixinType)) { return $this->metadataFactory->getMetadataForPhpcrType($mixinType); } } return; }
/** * {@inheritdoc} */ public function loadTranslation($document, NodeInterface $node, ClassMetadata $metadata, $locale) { if ($node->hasProperty($this->prefix . ':' . $locale . self::NULLFIELDS)) { $nullFields = $node->getPropertyValue($this->prefix . ':' . $locale . self::NULLFIELDS); $nullFields = array_flip($nullFields); } else { $nullFields = array(); } foreach ($metadata->translatableFields as $field) { $propName = $this->getTranslatedPropertyName($locale, $field); if (isset($nullFields[$field])) { $value = null; } elseif ($node->hasProperty($propName)) { $value = $node->getPropertyValue($propName); } else { // Could not find the translation in the given language return false; } $metadata->reflFields[$field]->setValue($document, $value); } return true; }
/** * Upgrade a single node. * * @param NodeInterface $node * @param string $propertyName * @param string $locale */ private function upgradeNode(NodeInterface $node, $propertyName, $locale) { foreach ($node->getNodes() as $child) { $this->upgradeNode($child, $propertyName, $locale); } if (false === $node->getPropertyValueWithDefault($propertyName, false)) { return; } $shadowLocale = $node->getPropertyValue($this->getPropertyName(self::SHADOW_BASE_PROPERTY, $locale)); $tags = $this->getTags($node, $shadowLocale); $categories = $this->getCategories($node, $shadowLocale); $navigationContext = $this->getNavigationContext($node, $shadowLocale); $node->setProperty(sprintf(self::TAGS_PROPERTY, $locale), $tags); $node->setProperty(sprintf(self::CATEGORIES_PROPERTY, $locale), $categories); $node->setProperty(sprintf(self::NAVIGATION_CONTEXT_PROPERTY, $locale), $navigationContext); }
/** * Updates the property for the resource segment on the given node. * * @param NodeInterface $node * @param string $resourceSegmentPropertyName * @param string $parentUuid * @param string $webspaceKey * @param string $locale */ private function updateResourceSegmentProperty(NodeInterface $node, $resourceSegmentPropertyName, $parentUuid, $webspaceKey, $locale) { $resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($webspaceKey); $childPart = $resourceLocatorStrategy->getChildPart($node->getPropertyValue($resourceSegmentPropertyName)); $node->setProperty($resourceSegmentPropertyName, $resourceLocatorStrategy->generate($childPart, $parentUuid, $webspaceKey, $locale)); }
/** * @param SessionInterface $session * @param NodeInterface $node * * @return bool|string FALSE if not mapped, string if url is mapped */ protected function mapUrl(SessionInterface $session, NodeInterface $node) { $phpcrClass = $node->getPropertyValue('phpcr:class'); if (!is_subclass_of($phpcrClass, 'Symfony\\Cmf\\Component\\Routing\\RouteReferrersReadInterface')) { return false; } try { $url = $this->router->generate(null, array('content_id' => $node->getIdentifier())); } catch (RouteNotFoundException $e) { return false; } return $url; }
/** * Check specified property exists, then compare property value to the supplied one using assertEquals. * * @param NodeInterface $node * @param string $property * @param mixed $value */ protected function checkNodeProperty(NodeInterface $node, $property, $value) { $this->assertTrue($node->hasProperty($property)); $this->assertEquals($value, $node->getPropertyValue($property)); }
/** * Upgrades the given property to the new date representation. * * @param PropertyMetadata $property * @param NodeInterface $node * @param bool $up */ private function upgradeProperty(PropertyMetadata $property, NodeInterface $node, $locale, $up) { $name = sprintf('i18n:%s-%s', $locale, $property->getName()); if (!$node->hasProperty($name)) { return; } $value = $node->getPropertyValue($name); if ($up) { $value = $this->upgradeDate($value); } else { $value = $this->downgradeDate($value); } $node->setProperty($name, $value); }
/** * Upgrades the node to new date representation. * * @param NodeInterface $node The node to be upgraded * @param string $locale The locale of the node to be upgraded * @param array $properties The properties which are or contain date fields$up */ private function upgradeNode(NodeInterface $node, $locale, $properties, $up) { foreach ($properties as $property) { $propertyName = $this->propertyEncoder->localizedContentName($property, $locale); if ($node->hasProperty($propertyName)) { $value = $this->upgradeProperty($node->getPropertyValue($propertyName), $up); $node->setProperty($propertyName, $value); } } }
/** * {@inheritdoc} */ public function getPropertyValue($name, $type = PropertyType::UNDEFINED) { return $this->node->getPropertyValue($name, $type); }
/** * {@inheritdoc} */ private function deleteByNode(NodeInterface $node, SessionInterface $session, $webspaceKey, $languageCode, $segmentKey = null) { if ($node->getPropertyValue('sulu:history') !== true) { // search for history nodes $this->iterateRouteNodes($node, function ($resourceLocator, NodeInterface $historyNode) use($session, $webspaceKey, $languageCode, $segmentKey) { // delete history nodes $this->deleteByNode($historyNode, $session, $webspaceKey, $languageCode, $segmentKey); }, $webspaceKey, $languageCode, $segmentKey); } $node->remove(); }
/** * Recursively output node and all its children into the file in the system * view format * * @param NodeInterface $node the node to output * @param resource $stream The stream resource (i.e. acquired with fopen) to * which the XML serialization of the subgraph will be output. Must * support the fwrite method. * @param boolean $skipBinary A boolean governing whether binary properties * are to be serialized. * @param boolean $noRecurse A boolean governing whether the subgraph at * absPath is to be recursed. * @param boolean $root Whether this is the root node of the resulting * document, meaning the namespace declarations have to be included in * it. */ private static function exportSystemViewRecursive(NodeInterface $node, NamespaceRegistryInterface $ns, $stream, $skipBinary, $noRecurse, $root = false) { fwrite($stream, '<sv:node'); if ($root) { self::exportNamespaceDeclarations($ns, $stream); } fwrite($stream, ' sv:name="' . (0 === $node->getDepth() ? 'jcr:root' : htmlspecialchars($node->getName())) . '">'); // the order MUST be primary type, then mixins, if any, then jcr:uuid if its a referenceable node fwrite($stream, '<sv:property sv:name="jcr:primaryType" sv:type="Name"><sv:value>' . htmlspecialchars($node->getPropertyValue('jcr:primaryType')) . '</sv:value></sv:property>'); if ($node->hasProperty('jcr:mixinTypes')) { fwrite($stream, '<sv:property sv:name="jcr:mixinTypes" sv:type="Name" sv:multiple="true">'); foreach ($node->getPropertyValue('jcr:mixinTypes') as $type) { fwrite($stream, '<sv:value>' . htmlspecialchars($type) . '</sv:value>'); } fwrite($stream, '</sv:property>'); } if ($node->isNodeType('mix:referenceable')) { fwrite($stream, '<sv:property sv:name="jcr:uuid" sv:type="String"><sv:value>' . $node->getIdentifier() . '</sv:value></sv:property>'); } foreach ($node->getProperties() as $name => $property) { /** @var $property \PHPCR\PropertyInterface */ if ($name == 'jcr:primaryType' || $name == 'jcr:mixinTypes' || $name == 'jcr:uuid') { // explicitly handled before continue; } if (PropertyType::BINARY == $property->getType() && $skipBinary) { // do not output binary data in the xml continue; } fwrite($stream, '<sv:property sv:name="' . htmlentities($name) . '" sv:type="' . PropertyType::nameFromValue($property->getType()) . '"' . ($property->isMultiple() ? ' sv:multiple="true"' : '') . '>'); $values = $property->isMultiple() ? $property->getString() : array($property->getString()); foreach ($values as $value) { if (PropertyType::BINARY == $property->getType()) { $val = base64_encode($value); } else { $val = htmlspecialchars($value); //TODO: can we still have invalid characters after this? if so base64 and property, xsi:type="xsd:base64Binary" } fwrite($stream, "<sv:value>{$val}</sv:value>"); } fwrite($stream, "</sv:property>"); } if (!$noRecurse) { foreach ($node as $child) { if (!($child->getDepth() == 1 && NodeHelper::isSystemItem($child))) { self::exportSystemViewRecursive($child, $ns, $stream, $skipBinary, $noRecurse); } } } fwrite($stream, '</sv:node>'); }