private function getStructureMock($name, $rlp = true) { $structureMock = $this->getMockForAbstractClass('\\Sulu\\Component\\Content\\Compat\\Structure\\Page', [$name, 'asdf', 'asdf', 2400]); $method = new ReflectionMethod(get_class($structureMock), 'addChild'); $method->setAccessible(true); $property = new Property('title', '', 'text_line', true, true, 1, 1, []); $property->setStructure($structureMock); $method->invokeArgs($structureMock, [$property]); if ($rlp) { $property = new Property('url', '', 'resource_locator', true, true, 1, 1, [], [new PropertyTag('sulu.rlp', 1)]); $property->setStructure($structureMock); $method->invokeArgs($structureMock, [$property]); } return $structureMock; }
/** * Create a new property. * * @param Item $item * * @return PropertyInterface $property */ public function createProperty(ItemMetadata $property, StructureInterface $structure = null) { if ($property instanceof SectionMetadata) { return $this->createSectionProperty($property, $structure); } if ($property instanceof BlockMetadata) { return $this->createBlockProperty($property, $structure); } if (null === $property->getType()) { throw new \RuntimeException(sprintf('Property name "%s" has no type.', $property->name)); } $parameters = $this->convertArrayToParameters($property->getParameters()); $propertyBridge = new LegacyProperty($property->getName(), ['title' => $property->title, 'info_text' => $property->description, 'placeholder' => $property->placeholder], $property->getType(), $property->isRequired(), $property->isLocalized(), $property->getMaxOccurs(), $property->getMinOccurs(), $parameters, [], $property->getColspan()); foreach ($property->tags as $tag) { $propertyBridge->addTag(new PropertyTag($tag['name'], $tag['priority'], $tag['attributes'])); } $propertyBridge->setStructure($structure); return $propertyBridge; }
/** * @HandlerCallback("json", direction = "deserialization") */ public function deserializeToJson(JsonDeserializationVisitor $visitor, $data, Context $context) { return parent::deserializeToJson($visitor, $data, $context); }
/** * Returns data for property. */ private function getPropertyData($document, LegacyProperty $property) { return $document->getStructure()->getContentViewProperty($property->getName())->getValue(); }
public function setPropertyValue(PropertyValue $value) { parent::setPropertyValue($value); $this->doSetValue($value); }
/** * Save the value from given property. * * @param NodeInterface $node * @param PropertyInterface $property * @param $userId * @param $webspaceKey * @param $languageCode * @param $segmentKey * @param bool $isImport * * @throws UnexpectedPropertyType */ private function doWrite(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey, $isImport = false) { if ($property->getIsBlock()) { /** @var BlockPropertyInterface $blockProperty */ $blockProperty = $property; while (!$blockProperty instanceof BlockPropertyInterface) { $blockProperty = $blockProperty->getProperty(); } $data = $blockProperty->getValue(); if (!$blockProperty->getIsMultiple()) { $data = [$data]; } $data = array_filter($data); $len = count($data); // init properties $typeProperty = new Property('type', '', 'text_line'); $lengthProperty = new Property('length', '', 'text_line'); //save length $lengthProperty->setValue($len); $contentType = $this->contentTypeManager->get($lengthProperty->getContentTypeName()); $contentType->write($node, new BlockPropertyWrapper($lengthProperty, $property), $userId, $webspaceKey, $languageCode, $segmentKey); for ($i = 0; $i < $len; ++$i) { $blockPropertyType = $blockProperty->getProperties($i); // save type property $this->writeProperty($typeProperty, $property, $blockPropertyType->getName(), $i, $node, $userId, $webspaceKey, $languageCode, $segmentKey, $isImport); foreach ($blockProperty->getProperties($i)->getChildProperties() as $subProperty) { $this->writeProperty($subProperty, $property, $subProperty->getValue(), $i, $node, $userId, $webspaceKey, $languageCode, $segmentKey, $isImport); } } } else { throw new UnexpectedPropertyType($property, $this); } }
public function testOverride() { $property = new Property('url', [], 'resource_locator'); $property->setValue('/test'); $node = $this->sessionManager->getContentNode('sulu_io')->addNode('test'); $node->addMixin('sulu:content'); $this->session->save(); $this->resourceLocator->write($node, $property, 1, 'sulu_io', 'en'); $this->assertEquals('/test', $node->getPropertyValue('url')); $this->assertTrue($this->session->getRootNode()->hasNode('cmf/sulu_io/routes/en/test')); $property->setValue('/test-2'); $this->resourceLocator->write($node, $property, 1, 'sulu_io', 'en'); $this->assertEquals('/test-2', $node->getPropertyValue('url')); $this->assertTrue($this->session->getRootNode()->hasNode('cmf/sulu_io/routes/en/test-2')); }