setValue() public method

sets the value from property.
public setValue ( mixed $value )
$value mixed
Exemplo n.º 1
0
 /**
  * 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);
     }
 }
Exemplo n.º 2
0
 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'));
 }