/**
  * Add dimensions to the node.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $dimensionValuesToBeAdded = $node->getDimensionValues();
     foreach ($this->dimensionValues as $dimensionName => $dimensionValues) {
         if (!isset($dimensionValuesToBeAdded[$dimensionName])) {
             if (is_array($dimensionValues)) {
                 $dimensionValuesToBeAdded[$dimensionName] = $dimensionValues;
             } else {
                 $dimensionValuesToBeAdded[$dimensionName] = array($dimensionValues);
             }
         }
     }
     if ($this->addDefaultDimensionValues === true) {
         $configuredDimensions = $this->contentDimensionRepository->findAll();
         foreach ($configuredDimensions as $configuredDimension) {
             if (!isset($dimensionValuesToBeAdded[$configuredDimension->getIdentifier()])) {
                 $dimensionValuesToBeAdded[$configuredDimension->getIdentifier()] = array($configuredDimension->getDefault());
             }
         }
     }
     $dimensionsToBeSet = array();
     foreach ($dimensionValuesToBeAdded as $dimensionName => $dimensionValues) {
         foreach ($dimensionValues as $dimensionValue) {
             $dimensionsToBeSet[] = new NodeDimension($node, $dimensionName, $dimensionValue);
         }
     }
     $node->setDimensions($dimensionsToBeSet);
 }
 /**
  * Returns TRUE if the given node has the default dimension values.
  *
  * @param \TYPO3\TYPO3CR\Domain\Model\NodeData $node
  * @return boolean
  */
 public function matches(\TYPO3\TYPO3CR\Domain\Model\NodeData $node)
 {
     if ($this->filterForDefaultDimensionValues === true) {
         $configuredDimensions = $this->contentDimensionRepository->findAll();
         foreach ($configuredDimensions as $dimension) {
             $this->dimensionValues[$dimension->getIdentifier()] = array($dimension->getDefault());
         }
     }
     return $node->getDimensionValues() === $this->dimensionValues;
 }
 /**
  * Generate a "Sites.xml" for the given package and name.
  *
  * @param string $packageKey
  * @param string $siteName
  * @return void
  */
 protected function generateSitesXml($packageKey, $siteName)
 {
     $templatePathAndFilename = 'resource://TYPO3.Neos.Kickstarter/Private/Generator/Content/Sites.xml';
     $contextVariables = array();
     $contextVariables['packageKey'] = $packageKey;
     $contextVariables['siteName'] = htmlspecialchars($siteName);
     $packageKeyDomainPart = substr(strrchr($packageKey, '.'), 1) ?: $packageKey;
     $contextVariables['siteNodeName'] = strtolower($packageKeyDomainPart);
     $contextVariables['dimensions'] = $this->contentDimensionRepository->findAll();
     $fileContent = $this->renderTemplate($templatePathAndFilename, $contextVariables);
     $sitesXmlPathAndFilename = $this->packageManager->getPackage($packageKey)->getResourcesPath() . 'Private/Content/Sites.xml';
     $this->generateFile($sitesXmlPathAndFilename, $fileContent);
 }
 /**
  * @test
  */
 public function adoptNodeWithExistingNodeMatchingTargetDimensionValuesWillReuseNode()
 {
     $this->contentDimensionRepository->setDimensionsConfiguration(['test' => ['default' => 'a']]);
     $variantContextA = $this->contextFactory->create(['dimensions' => ['test' => ['a']], 'targetDimensions' => ['test' => 'a']]);
     $variantContextB = $this->contextFactory->create(['dimensions' => ['test' => ['b', 'a']], 'targetDimensions' => ['test' => 'b']]);
     $variantContextA->getRootNode()->getNodeData()->createNodeData('test', null, null, $variantContextA->getWorkspace(), ['test' => ['a', 'b']]);
     $this->persistenceManager->persistAll();
     $variantNodeA = $variantContextA->getRootNode()->getNode('test');
     $variantNodeB = $variantContextB->adoptNode($variantNodeA);
     $this->assertSame($variantNodeA->getDimensions(), $variantNodeB->getDimensions());
 }
 /**
  * Change the property on the given node.
  *
  * @param \TYPO3\TYPO3CR\Domain\Model\NodeData $node
  * @return void
  */
 public function execute(\TYPO3\TYPO3CR\Domain\Model\NodeData $node)
 {
     $dimensions = array();
     foreach ($this->dimensionValues as $dimensionName => $dimensionConfiguration) {
         foreach ($dimensionConfiguration as $dimensionValues) {
             if (is_array($dimensionValues)) {
                 foreach ($dimensionValues as $dimensionValue) {
                     $dimensions[] = new NodeDimension($node, $dimensionName, $dimensionValue);
                 }
             } else {
                 $dimensions[] = new NodeDimension($node, $dimensionName, $dimensionValues);
             }
         }
     }
     if ($this->addDefaultDimensionValues === TRUE) {
         $configuredDimensions = $this->contentDimensionRepository->findAll();
         foreach ($configuredDimensions as $configuredDimension) {
             if (!isset($this->dimensionValues[$configuredDimension->getIdentifier()])) {
                 $dimensions[] = new NodeDimension($node, $configuredDimension->getIdentifier(), $configuredDimension->getDefault());
             }
         }
     }
     $node->setDimensions($dimensions);
 }
 /**
  * @test
  */
 public function nodesInPathAreHiddenIfBetterVariantInOtherPathExists()
 {
     $this->contentDimensionRepository->setDimensionsConfiguration(['test' => ['default' => 'a']]);
     $variantContextA = $this->contextFactory->create(['dimensions' => ['test' => ['a']], 'targetDimensions' => ['test' => 'a']]);
     $container1 = $variantContextA->getRootNode()->createNode('container1');
     $variantContextA->getRootNode()->createNode('container2');
     $container1->createNode('node-with-variant');
     $variantContextB = $this->contextFactory->create(['dimensions' => ['test' => ['b', 'a']], 'targetDimensions' => ['test' => 'b']]);
     $nodeWithVariantOriginal = $variantContextB->getNode('/container1/node-with-variant');
     $variantContextB->getNode('/container2')->createNode('node-with-variant', null, $nodeWithVariantOriginal->getIdentifier());
     $this->persistenceManager->persistAll();
     $this->contextFactory->reset();
     $variantContextB = $this->contextFactory->create(['dimensions' => ['test' => ['b', 'a']], 'targetDimensions' => ['test' => 'b']]);
     // Both containers should be available due to fallbacks
     $this->assertCount(2, $variantContextB->getRootNode()->getChildNodes());
     // This should NOT find the node created in variantContextA as
     // a better matching (with "b" dimension value) variant (same identifier) exists in container two
     $this->assertCount(0, $variantContextB->getNode('/container1')->getChildNodes());
     // This is the better matching variant and should be found.
     $this->assertCount(1, $variantContextB->getNode('/container2')->getChildNodes());
 }
 /**
  * @return array<\TYPO3\TYPO3CR\Domain\Model\ContentDimension>
  */
 protected function getAvailableDimensions()
 {
     return $this->contentDimensionRepository->findAll();
 }
 /**
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     $this->inject($this->contextFactory, 'contextInstances', array());
     $this->contentDimensionRepository->setDimensionsConfiguration(array());
 }