/** * {@inheritDoc} */ public function writeMetadata(DocumentManagerInterface $dm, NodeInterface $node, $className) { $className = $this->expandClassName($dm, $className); if ('Doctrine\\ODM\\PHPCR\\Document\\Generic' !== $className) { $node->setProperty('phpcr:class', $className, PropertyType::STRING); $class = $dm->getClassMetadata($className); $node->setProperty('phpcr:classparents', $class->getParentClasses(), PropertyType::STRING); } }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $value = $property->getValue(); if ($value !== null && $value !== false && $value !== 'false' && $value !== '') { $node->setProperty($property->getName(), true); } else { $node->setProperty($property->getName(), false); } }
public function testSaveWithoutData() { $content = []; $this->node->setProperty(Argument::any(), Argument::any())->will(function ($arguments) use(&$content) { $content[$arguments[0]] = $arguments[1]; }); $data = []; $this->extension->setLanguageCode('de', 'i18n', null); $this->extension->save($this->node->reveal(), $data, 'default', 'de'); $this->assertEquals(['i18n:de-seo-title' => '', 'i18n:de-seo-description' => '', 'i18n:de-seo-keywords' => '', 'i18n:de-seo-canonicalUrl' => '', 'i18n:de-seo-noIndex' => false, 'i18n:de-seo-noFollow' => false, 'i18n:de-seo-hideInSitemap' => false], $content); }
protected function fromJsonLD(NodeInterface $node, array $data) { unset($data['@'], $data['a']); foreach ($data as $key => $value) { $node->setProperty($key, $value); } }
/** * {@inheritdoc} */ public function saveTranslation(array $data, NodeInterface $node, ClassMetadata $metadata, $locale) { $nullFields = array(); foreach ($data as $field => $propValue) { $propName = $this->getTranslatedPropertyName($locale, $field); $node->setProperty($propName, $propValue); if (null === $propValue) { $nullFields[] = $field; } } if (empty($nullFields)) { $nullFields = null; } $node->setProperty($this->prefix . ':' . $locale . self::NULLFIELDS, $nullFields); // no '-' to avoid nameclashes }
/** * {@inheritdoc} */ public function setProperty($name, $value, $type = PropertyType::UNDEFINED) { $oldValue = $this->getPropertyValueWithDefault($name, null); if ($oldValue !== null && gettype($value) !== gettype($oldValue)) { $this->node->getProperty($name)->remove(); } return $this->node->setProperty($name, $value, $type); }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $value = $property->getValue(); if ($value !== null) { $node->setProperty($property->getName(), $this->removeValidation($this->removeIllegalCharacters($value))); } else { $this->remove($node, $property, $webspaceKey, $languageCode, $segmentKey); } }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $tagIds = []; $tags = $property->getValue() === null ? [] : $property->getValue(); foreach ($tags as $tag) { $tagIds[] = $this->tagManager->findOrCreateByName($tag, $userId)->getId(); } $node->setProperty($property->getName(), $tagIds); }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $value = $property->getValue(); if ($value != null) { $value = \DateTime::createFromFormat('Y-m-d', $value); $node->setProperty($property->getName(), $value); } else { $this->remove($node, $property, $webspaceKey, $languageCode, $segmentKey); } }
/** * Process - or update - a given node. * * Provides common processing for both touch and update commands. * * @param OutputInterface $output used for status updates. * @param NodeInterface $node the node to manipulate. * @param array $operations to execute on that node. */ public function processNode(OutputInterface $output, NodeInterface $node, array $operations) { $operations = array_merge(array('setProp' => array(), 'removeProp' => array(), 'addMixins' => array(), 'removeMixins' => array(), 'applyClosures' => array(), 'dump' => false), $operations); foreach ($operations['setProp'] as $set) { $parts = explode('=', $set); $output->writeln(sprintf('<comment> > Setting property </comment>%s<comment> to </comment>%s', $parts[0], $parts[1])); $node->setProperty($parts[0], $parts[1]); } foreach ($operations['removeProp'] as $unset) { $output->writeln(sprintf('<comment> > Unsetting property </comment>%s', $unset)); $node->setProperty($unset, null); } foreach ($operations['addMixins'] as $addMixin) { $output->writeln(sprintf('<comment> > Adding mixin </comment>%s', $addMixin)); $node->addMixin($addMixin); } foreach ($operations['removeMixins'] as $removeMixin) { $output->writeln(sprintf('<comment> > Removing mixin </comment>%s', $removeMixin)); $node->removeMixin($removeMixin); } foreach ($operations['applyClosures'] as $closure) { if ($closure instanceof \Closure) { $output->writeln('<comment> > Applying closure</comment>'); } else { $closureString = $closure; $closure = create_function('$session, $node', $closure); $output->writeln(sprintf('<comment> > Applying closure: %s</comment>', strlen($closureString) > 75 ? substr($closureString, 0, 72) . '...' : $closureString)); } $closure($this->session, $node); } if ($operations['dump']) { $output->writeln('<info>Node dump: </info>'); /** @var $property PropertyInterface */ foreach ($node->getProperties() as $property) { $value = $property->getValue(); if (!is_string($value)) { $value = print_r($value, true); } $output->writeln(sprintf('<comment> - %s = </comment>%s', $property->getName(), $value)); } } }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $value = $property->getValue(); if ($value instanceof ArrayableInterface) { $value = $value->toArray(); } // if whole smart-content container is pushed if (isset($value['data'])) { unset($value['data']); } // set value to node $node->setProperty($property->getName(), json_encode($value)); }
public function testRemove() { $type = new ContactSelectionContentType($this->template, $this->contactManager->reveal(), $this->accountManager->reveal(), $this->serializer->reveal(), new CustomerIdConverter(), new IndexComparator()); $nodeProperty = $this->prophesize(\PHPCR\PropertyInterface::class); $nodeProperty->remove()->shouldBeCalled(); $nodeProperty->setValue(Argument::any())->shouldNotBeCalled(); $nodeProperty->getValue(Argument::any())->shouldNotBeCalled(); $this->property->getName()->willReturn('test'); $this->property->getValue()->shouldNotBeCalled(); $this->node->hasProperty('test')->willReturn(true); $this->node->getProperty('test')->willReturn($nodeProperty->reveal()); $this->node->setProperty(Argument::any(), Argument::any())->shouldNotBeCalled(); $type->remove($this->node->reveal(), $this->property->reveal(), $this->webspaceKey, $this->locale, $this->segmentKey); }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $categoryIds = []; $value = $property->getValue(); if (null === $value) { $node->setProperty($property->getName(), null); return; } foreach ($value as $category) { if (is_numeric($category)) { // int value for id $categoryIds[] = $category; } else { // full category object use only id to save $categoryIds[] = $category['id']; } } $node->setProperty($property->getName(), $categoryIds); }
/** * Set the mapped mixins. * * @param ClassMetadata $metadata * @param NodeInterface $node * @param object $document The document to update autogenerated fields. */ private function setMixins(Mapping\ClassMetadata $metadata, NodeInterface $node, $document) { $repository = $this->session->getRepository(); if ($metadata->versionable === 'full') { if ($repository->getDescriptor(RepositoryInterface::OPTION_VERSIONING_SUPPORTED)) { $node->addMixin('mix:versionable'); } elseif ($repository->getDescriptor(RepositoryInterface::OPTION_SIMPLE_VERSIONING_SUPPORTED)) { $node->addMixin('mix:simpleVersionable'); } } elseif ($metadata->versionable === 'simple' && $repository->getDescriptor(RepositoryInterface::OPTION_SIMPLE_VERSIONING_SUPPORTED)) { $node->addMixin('mix:simpleVersionable'); } if (!$node->isNodeType('mix:referenceable') && $metadata->referenceable) { $node->addMixin('mix:referenceable'); } // manually set the uuid if it is not present yet, so we can assign it to documents if ($node->isNodeType('mix:referenceable') && !$node->hasProperty('jcr:uuid')) { $uuid = false; $uuidFieldName = $metadata->getUuidFieldName(); if ($uuidFieldName) { $uuid = $metadata->getFieldValue($document, $uuidFieldName); } if (!$uuid) { $uuid = $this->generateUuid(); } $node->setProperty('jcr:uuid', $uuid); if ($uuidFieldName && !$metadata->getFieldValue($document, $uuidFieldName)) { $metadata->setFieldValue($document, $uuidFieldName, $uuid); } } }
/** * Write any relevant meta data into the node to be able to map back to a class name later * * @param DocumentManager * @param NodeInterface $node * @param string $className */ public function writeMetadata(DocumentManager $dm, NodeInterface $node, $className) { $node->setProperty('phpcr:class', $className, PropertyType::STRING); }
/** * Write any relevant meta data into the node to be able to map back to a class name later * * @param DocumentManager * @param NodeInterface $node * @param string $className */ public function writeMetadata(DocumentManager $dm, NodeInterface $node, $className) { if ('Doctrine\\ODM\\PHPCR\\Document\\Generic' !== $className) { $node->setProperty('phpcr:class', $className, PropertyType::STRING); } }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $snippetReferences = []; $values = $property->getValue(); $values = is_array($values) ? $values : []; foreach ($values as $value) { if ($value instanceof SnippetBridge) { $snippetReferences[] = $value->getUuid(); } elseif (is_array($value) && array_key_exists('uuid', $value) && UUIDHelper::isUUID($value['uuid'])) { $snippetReferences[] = $value['uuid']; } elseif (UUIDHelper::isUUID($value)) { $snippetReferences[] = $value; } else { throw new \InvalidArgumentException(sprintf('Property value must either be a UUID or a Snippet, "%s" given.', gettype($value))); } } $node->setProperty($property->getName(), $snippetReferences, PropertyType::REFERENCE); }
/** * save a single property value. * * @param NodeInterface $node * @param array $data data array * @param string $name name of property in node an data array * @param string $default value if no data exists with given name * @param string $default */ protected function saveProperty(NodeInterface $node, $data, $name, $default = '') { $value = isset($data[$name]) ? $data[$name] : $default; $node->setProperty($this->getPropertyName($name), $value); }
/** * Sets the workflow stage properties on the given node. * * @param NodeInterface $node * @param string $locale * @param int $workflowStage * @param bool $updatePublished */ private function setWorkflowStageOnNode(NodeInterface $node, $locale, $workflowStage, $updatePublished) { $node->setProperty($this->propertyEncoder->localizedSystemName(self::WORKFLOW_STAGE_FIELD, $locale), $workflowStage); if ($updatePublished) { $node->setProperty($this->propertyEncoder->localizedSystemName(self::PUBLISHED_FIELD, $locale), new \DateTime()); } }
/** * {@inheritdoc} */ public function save(NodeInterface $node, $data, $webspaceKey, $languageCode) { $node->setProperty($this->getPropertyName('a'), $data['a']); $node->setProperty($this->getPropertyName('b'), $data['b']); }
/** * 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)); }
/** * 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 write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $value = $property->getValue(); if ($value instanceof ArrayableInterface) { $value = $value->toArray(); } // if whole smart-content container is pushed if (isset($value['config'])) { $value = $value['config']; } if (!empty($value['tags'])) { $value['tags'] = $this->tagManager->resolveTagNames($value['tags']); } $node->setProperty($property->getName(), json_encode($value)); }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $value = $property->getValue(); if ($value instanceof ArrayableInterface) { $value = $value->toArray(); } $this->resolveTags($value, 'tags'); $this->resolveTags($value, 'websiteTags'); $node->setProperty($property->getName(), json_encode($value)); }
/** * 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); }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $value = $property->getValue(); if ($value instanceof ArrayableInterface) { $value = $value->toArray(); } if (isset($value)) { // remove not existing ids $session = $node->getSession(); $selectedNodes = $session->getNodesByIdentifier($value); $ids = []; foreach ($selectedNodes as $selectedNode) { if ($selectedNode->getIdentifier() === $node->getIdentifier()) { throw new \InvalidArgumentException('You are not allowed to link a page to itself!'); } $ids[] = $selectedNode->getIdentifier(); } $value = $ids; } // set value to node $node->setProperty($property->getName(), $value, PropertyType::REFERENCE); }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $value = $property->getValue(); $node->setProperty($property->getName(), $value === null ? [] : $value); }
private function setMixins(Mapping\ClassMetadata $metadata, NodeInterface $node) { if ($metadata->versionable === 'full') { $node->addMixin('mix:versionable'); } else { if ($metadata->versionable === 'simple') { $node->addMixin('mix:simpleVersionable'); } if ($metadata->referenceable) { $node->addMixin('mix:referenceable'); } } // we manually set the uuid to allow creating referenced and referencing document without flush in between. if ($node->isNodeType('mix:referenceable') && !$node->hasProperty('jcr:uuid')) { // TODO do we need to check with the storage backend if the generated id really is unique? $node->setProperty('jcr:uuid', UUIDHelper::generateUUID()); } }
/** * changes path node to history node. * * @param NodeInterface $node * @param SessionInterface $session * @param string $absSrcPath * @param string $absDestPath */ private function changePathToHistory(NodeInterface $node, SessionInterface $session, $absSrcPath, $absDestPath) { // get new path node $relPath = str_replace($absSrcPath, '', $node->getPath()); $newPath = PathHelper::normalizePath($absDestPath . $relPath); $newPathNode = $session->getNode($newPath); // set history to true and set content to new path $node->setProperty('sulu:content', $newPathNode); $node->setProperty('sulu:history', true); // get referenced history /** @var PropertyInterface $property */ foreach ($node->getReferences('sulu:content') as $property) { $property->getParent()->setProperty('sulu:content', $newPathNode); } }
/** * @inheritDoc * * Remove the (untranslated) fields listed in $metadata->translatableFields */ public function removeAllTranslations($document, NodeInterface $node, ClassMetadata $metadata) { foreach ($metadata->translatableFields as $field) { $mapping = $metadata->mappings[$field]; $node->setProperty($mapping['property'], null); } }