/**
  * Builds the array of Menu items for this variant menu
  */
 protected function buildItems()
 {
     $menuItems = [];
     $targetDimensionsToMatch = [];
     $allDimensionPresets = $this->configurationContentDimensionPresetSource->getAllPresets();
     $includeAllPresets = $this->getIncludeAllPresets();
     $pinnedDimensionValues = $this->getPresets();
     $pinnedDimensionName = $this->getDimension();
     if ($pinnedDimensionName !== null) {
         $targetDimensionsToMatch = $this->currentNode->getContext()->getTargetDimensions();
         unset($targetDimensionsToMatch[$pinnedDimensionName]);
     }
     foreach ($this->contentDimensionCombinator->getAllAllowedCombinations() as $allowedCombination) {
         $targetDimensions = $this->calculateTargetDimensionsForCombination($allowedCombination);
         if ($pinnedDimensionName !== null && is_array($pinnedDimensionValues)) {
             if (!in_array($targetDimensions[$pinnedDimensionName], $pinnedDimensionValues)) {
                 continue;
             }
         }
         // skip variants not matching the current target dimensions (except the dimension this menu covers)
         if ($targetDimensionsToMatch !== []) {
             foreach ($targetDimensionsToMatch as $dimensionName => $dimensionValue) {
                 if ($targetDimensions[$dimensionName] !== $dimensionValue) {
                     continue 2;
                 }
             }
         }
         $nodeInDimensions = $this->getNodeInDimensions($allowedCombination, $targetDimensions);
         // no match, so we look further...
         if ($nodeInDimensions === null && $includeAllPresets) {
             $nodeInDimensions = $this->findAcceptableNode($allowedCombination, $allDimensionPresets);
         }
         if ($nodeInDimensions !== null && $this->isNodeHidden($nodeInDimensions)) {
             $nodeInDimensions = null;
         }
         // determine metadata for target dimensions of node
         array_walk($targetDimensions, function (&$dimensionValue, $dimensionName, $allDimensionPresets) use($pinnedDimensionName) {
             $dimensionValue = ['value' => $dimensionValue, 'label' => $allDimensionPresets[$dimensionName]['presets'][$dimensionValue]['label'], 'isPinnedDimension' => $pinnedDimensionName === null || $dimensionName == $pinnedDimensionName ? true : false];
         }, $allDimensionPresets);
         if ($pinnedDimensionName === null) {
             $itemLabel = $nodeInDimensions->getLabel();
         } else {
             $itemLabel = $targetDimensions[$pinnedDimensionName]['label'];
         }
         $menuItems[] = ['node' => $nodeInDimensions, 'state' => $this->calculateItemState($nodeInDimensions), 'label' => $itemLabel, 'dimensions' => $allowedCombination, 'targetDimensions' => $targetDimensions];
     }
     // sort/limit according to configured "presets" if needed
     if ($pinnedDimensionName !== null && is_array($pinnedDimensionValues)) {
         $sortedMenuItems = [];
         foreach ($pinnedDimensionValues as $pinnedDimensionValue) {
             foreach ($menuItems as $menuItemKey => $menuItem) {
                 if ($menuItem['targetDimensions'][$pinnedDimensionName]['value'] === $pinnedDimensionValue) {
                     $sortedMenuItems[$menuItemKey] = $menuItem;
                 }
             }
         }
         return $sortedMenuItems;
     }
     return $menuItems;
 }
 /**
  * Generate missing URI path segments
  *
  * This generates URI path segment properties for all document nodes which don't have
  * a path segment set yet.
  *
  * @param string $workspaceName
  * @param boolean $dryRun
  * @return void
  */
 public function generateUriPathSegments($workspaceName, $dryRun)
 {
     $baseContext = $this->createContext($workspaceName, []);
     $baseContextSitesNode = $baseContext->getNode(SiteService::SITES_ROOT_PATH);
     if (!$baseContextSitesNode) {
         $this->output->outputLine('<error>Could not find "' . SiteService::SITES_ROOT_PATH . '" root node</error>');
         return;
     }
     $baseContextSiteNodes = $baseContextSitesNode->getChildNodes();
     if ($baseContextSiteNodes === []) {
         $this->output->outputLine('<error>Could not find any site nodes in "' . SiteService::SITES_ROOT_PATH . '" root node</error>');
         return;
     }
     foreach ($this->dimensionCombinator->getAllAllowedCombinations() as $dimensionCombination) {
         $flowQuery = new FlowQuery($baseContextSiteNodes);
         $siteNodes = $flowQuery->context(['dimensions' => $dimensionCombination, 'targetDimensions' => []])->get();
         if (count($siteNodes) > 0) {
             $this->output->outputLine('Checking for nodes with missing URI path segment in dimension "%s"', array(trim(NodePaths::generateContextPath('', '', $dimensionCombination), '@;')));
             foreach ($siteNodes as $siteNode) {
                 $this->generateUriPathSegmentsForNode($siteNode, $dryRun);
             }
         }
     }
     $this->persistenceManager->persistAll();
 }
 /**
  * Remove nodes with invalid dimension values
  *
  * This removes nodes which have dimension values not fitting to the current dimension configuration
  *
  * @param string $workspaceName Name of the workspace to consider
  * @param boolean $dryRun Simulate?
  * @return void
  */
 public function removeNodesWithInvalidDimensions($workspaceName, $dryRun)
 {
     $this->output->outputLine('Checking for nodes with invalid dimensions ...');
     $allowedDimensionCombinations = $this->contentDimensionCombinator->getAllAllowedCombinations();
     $nodesArray = $this->collectNodesWithInvalidDimensions($workspaceName, $allowedDimensionCombinations);
     if ($nodesArray === []) {
         return;
     }
     if (!$dryRun) {
         $self = $this;
         $this->output->outputLine();
         $this->output->outputLine('Nodes with invalid dimension values found.' . PHP_EOL . 'You might solve this by migrating them to your current dimension configuration or by removing them.');
         $this->askBeforeExecutingTask(sprintf('Do you want to remove %s node%s with invalid dimensions now?', count($nodesArray), count($nodesArray) > 1 ? 's' : ''), function () use($self, $nodesArray, $workspaceName) {
             foreach ($nodesArray as $nodeArray) {
                 $self->removeNode($nodeArray['identifier'], $nodeArray['dimensionsHash']);
             }
             $self->output->outputLine('Removed %s node%s with invalid dimension values.', array(count($nodesArray), count($nodesArray) > 1 ? 's' : ''));
         });
     } else {
         $this->output->outputLine('Found %s node%s with invalid dimension values to be removed.', array(count($nodesArray), count($nodesArray) > 1 ? 's' : ''));
     }
     $this->output->outputLine();
 }