similarize() публичный Метод

Make the node "similar" to the given source node. That means, - all properties - index - node type - content object will be set to the same values as in the source node.
public similarize ( AbstractNodeData $sourceNode, boolean $isCopy = false ) : void
$sourceNode AbstractNodeData
$isCopy boolean
Результат void
 /**
  * @test
  */
 public function similarizeClearsPropertiesBeforeAddingNewOnes()
 {
     /** @var $sourceNode NodeData */
     $sourceNode = $this->getAccessibleMock(NodeData::class, array('addOrUpdate'), array('/foo/bar', $this->mockWorkspace));
     $this->inject($sourceNode, 'nodeTypeManager', $this->mockNodeTypeManager);
     $sourceNode->_set('nodeDataRepository', $this->createMock(RepositoryInterface::class));
     $this->nodeData->setProperty('someProperty', 'somePropertyValue');
     $this->nodeData->setProperty('someOtherProperty', 'someOtherPropertyValue');
     $sourceNode->setProperty('newProperty', 'newPropertyValue');
     $sourceNode->setProperty('someProperty', 'someOverriddenPropertyValue');
     $this->nodeData->similarize($sourceNode);
     $expectedProperties = array('newProperty' => 'newPropertyValue', 'someProperty' => 'someOverriddenPropertyValue');
     $this->assertEquals($expectedProperties, $this->nodeData->getProperties());
 }
Пример #2
0
 /**
  * Create a shadow NodeData at the given path with the same workspace and dimensions as this
  *
  * Note: The constructor will already add the new object to the repository
  * Internal method, do not use outside of the content repository.
  *
  * @param string $path The (original) path for the node data
  * @return NodeData
  */
 public function createShadow($path)
 {
     $shadowNode = new NodeData($path, $this->workspace, $this->identifier, $this->dimensionValues);
     $shadowNode->similarize($this);
     $shadowNode->setAsShadowOf($this);
     return $shadowNode;
 }
Пример #3
0
 /**
  * Given a context a new node is returned that is like this node, but
  * lives in the new context.
  *
  * @param Context $context
  * @return NodeInterface
  */
 public function createVariantForContext($context)
 {
     $autoCreatedChildNodes = [];
     $nodeType = $this->getNodeType();
     foreach ($nodeType->getAutoCreatedChildNodes() as $childNodeName => $childNodeConfiguration) {
         $childNode = $this->getNode($childNodeName);
         if ($childNode !== null) {
             $autoCreatedChildNodes[$childNodeName] = $childNode;
         }
     }
     $nodeData = new NodeData($this->nodeData->getPath(), $context->getWorkspace(), $this->nodeData->getIdentifier(), $context->getTargetDimensionValues());
     $nodeData->similarize($this->nodeData);
     if ($this->context !== $context) {
         $node = $this->nodeFactory->createFromNodeData($nodeData, $context);
     } else {
         $this->setNodeData($nodeData);
         $node = $this;
     }
     $this->context->getFirstLevelNodeCache()->flush();
     $this->emitNodeAdded($node);
     /**
      * @var $autoCreatedChildNode NodeInterface
      */
     foreach ($autoCreatedChildNodes as $autoCreatedChildNode) {
         $autoCreatedChildNode->createVariantForContext($context);
     }
     return $node;
 }