It allows to find a matching preset for a list of dimension values. Or calculate all dimension combinations for you (the matrix of all configured presets). Content Dimension Preset ======================== A Content Dimension Preset assigns an identifier to a (fallback) list of dimension values. It can have additional properties like UI label and icon and further options for routing if needed. The default implementation ConfigurationContentDimensionPresetSource will read the available presets from settings.
 /**
  * Creates a new content context based on the given workspace and the NodeData object.
  *
  * @param Workspace $workspace Workspace for the new context
  * @param array $dimensionValues The dimension values for the new context
  * @param array $contextProperties Additional pre-defined context properties
  * @return Context
  */
 protected function createContext(Workspace $workspace, array $dimensionValues, array $contextProperties = array())
 {
     $presetsMatchingDimensionValues = $this->contentDimensionPresetSource->findPresetsByTargetValues($dimensionValues);
     $dimensions = array_map(function ($preset) {
         return $preset['values'];
     }, $presetsMatchingDimensionValues);
     $contextProperties += array('workspaceName' => $workspace->getName(), 'inaccessibleContentShown' => true, 'invisibleContentShown' => true, 'removedContentShown' => true, 'dimensions' => $dimensions);
     return $this->contextFactory->create($contextProperties);
 }
 /**
  * Array of all possible dimension configurations allowed by configured presets.
  *
  * @return array
  */
 public function getAllAllowedCombinations()
 {
     $configuration = $this->contentDimensionPresetSource->getAllPresets();
     $dimensionCombinations = [];
     $dimensionNames = array_keys($configuration);
     $dimensionCount = count($dimensionNames);
     if ($dimensionCount === 0) {
         // This is correct, we have one allowed combination which is no dimension values (empty array).
         return [[]];
     }
     // Reset all presets first just to be sure
     foreach ($configuration as $dimensionName => &$dimensionConfiguration) {
         reset($dimensionConfiguration['presets']);
     }
     unset($dimensionConfiguration);
     while (true) {
         $skipCurrentCombination = false;
         $currentPresetCombination = ['withPresetIdentifiers' => [], 'withDimensionValues' => []];
         foreach ($dimensionNames as $dimensionName) {
             $presetIdentifierForDimension = key($configuration[$dimensionName]['presets']);
             $presetForDimension = current($configuration[$dimensionName]['presets']);
             if (!is_array($presetForDimension) || !isset($presetForDimension['values'])) {
                 $skipCurrentCombination = true;
             }
             $currentPresetCombination['withPresetIdentifiers'][$dimensionName] = $presetIdentifierForDimension;
             $currentPresetCombination['withDimensionValues'][$dimensionName] = $presetForDimension['values'];
         }
         if ($skipCurrentCombination === false && $this->contentDimensionPresetSource->isPresetCombinationAllowedByConstraints($currentPresetCombination['withPresetIdentifiers'])) {
             $dimensionCombinations[] = $currentPresetCombination['withDimensionValues'];
         }
         $nextDimension = 0;
         $hasValue = next($configuration[$dimensionNames[$nextDimension]]['presets']);
         while ($hasValue === false) {
             reset($configuration[$dimensionNames[$nextDimension]]['presets']);
             $nextDimension++;
             if (!isset($dimensionNames[$nextDimension])) {
                 // we have gone through all dimension combinations now.
                 return $dimensionCombinations;
             }
             $hasValue = next($configuration[$dimensionNames[$nextDimension]]['presets']);
         }
     }
 }
 /**
  * Matches if the currently-selected preset in the passed $dimensionName is one of $presets.
  *
  * Example: isInDimensionPreset('language', 'de') checks whether the currently-selected language
  * preset (in the Neos backend) is "de".
  *
  * Implementation Note: We deliberately work on the Dimension Preset Name, and not on the
  * dimension values itself; as the preset is user-visible and the actual dimension-values
  * for a preset are just implementation details.
  *
  * @param string $dimensionName
  * @param string|array $presets
  * @return boolean
  */
 public function isInDimensionPreset($dimensionName, $presets)
 {
     if ($this->node === null) {
         return true;
     }
     $dimensionValues = $this->node->getContext()->getDimensions();
     if (!isset($dimensionValues[$dimensionName])) {
         return false;
     }
     $preset = $this->contentDimensionPresetSource->findPresetByDimensionValues($dimensionName, $dimensionValues[$dimensionName]);
     if ($preset === null) {
         return false;
     }
     $presetIdentifier = $preset['identifier'];
     if (!is_array($presets)) {
         $presets = array($presets);
     }
     return in_array($presetIdentifier, $presets);
 }
 public function setUp()
 {
     $this->publishingService = new PublishingService();
     $this->mockWorkspaceRepository = $this->getMockBuilder(WorkspaceRepository::class)->disableOriginalConstructor()->setMethods(array('findOneByName'))->getMock();
     $this->inject($this->publishingService, 'workspaceRepository', $this->mockWorkspaceRepository);
     $this->mockNodeDataRepository = $this->getMockBuilder(NodeDataRepository::class)->disableOriginalConstructor()->setMethods(array('findByWorkspace'))->getMock();
     $this->inject($this->publishingService, 'nodeDataRepository', $this->mockNodeDataRepository);
     $this->mockNodeFactory = $this->getMockBuilder(NodeFactory::class)->disableOriginalConstructor()->getMock();
     $this->inject($this->publishingService, 'nodeFactory', $this->mockNodeFactory);
     $this->mockContextFactory = $this->getMockBuilder(ContextFactoryInterface::class)->disableOriginalConstructor()->getMock();
     $this->inject($this->publishingService, 'contextFactory', $this->mockContextFactory);
     $this->mockBaseWorkspace = $this->getMockBuilder(Workspace::class)->disableOriginalConstructor()->getMock();
     $this->mockBaseWorkspace->expects($this->any())->method('getName')->will($this->returnValue('live'));
     $this->mockBaseWorkspace->expects($this->any())->method('getBaseWorkspace')->will($this->returnValue(null));
     $this->mockContentDimensionPresetSource = $this->getMockBuilder(ContentDimensionPresetSourceInterface::class)->disableOriginalConstructor()->getMock();
     $this->mockContentDimensionPresetSource->expects($this->any())->method('findPresetsByTargetValues')->will($this->returnArgument(0));
     $this->inject($this->publishingService, 'contentDimensionPresetSource', $this->mockContentDimensionPresetSource);
     $this->mockWorkspace = $this->getMockBuilder(Workspace::class)->disableOriginalConstructor()->getMock();
     $this->mockWorkspace->expects($this->any())->method('getName')->will($this->returnValue('workspace-name'));
     $this->mockWorkspace->expects($this->any())->method('getBaseWorkspace')->will($this->returnValue($this->mockBaseWorkspace));
 }