/**
  * 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 NodeData $node
  * @return boolean
  */
 public function matches(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;
 }
Exemplo n.º 3
0
 /**
  * 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://Neos.SiteKickstarter/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 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<\Neos\ContentRepository\Domain\Model\ContentDimension>
  */
 protected function getAvailableDimensions()
 {
     return $this->contentDimensionRepository->findAll();
 }