/**
  * Find a URI segment in the content dimension presets for the given "language" dimension values
  *
  * This will do a reverse lookup from actual dimension values to a preset and fall back to the default preset if none
  * can be found.
  *
  * @param array $dimensionsValues An array of dimensions and their values, indexed by dimension name
  * @param boolean $currentNodeIsSiteNode If the current node is actually the site node
  * @return string
  * @throws \Exception
  */
 protected function getUriSegmentForDimensions(array $dimensionsValues, $currentNodeIsSiteNode)
 {
     $uriSegment = '';
     $allDimensionPresetsAreDefault = TRUE;
     foreach ($this->contentDimensionPresetSource->getAllPresets() as $dimensionName => $dimensionPresets) {
         $preset = NULL;
         if (isset($dimensionsValues[$dimensionName])) {
             $preset = $this->contentDimensionPresetSource->findPresetByDimensionValues($dimensionName, $dimensionsValues[$dimensionName]);
         }
         $defaultPreset = $this->contentDimensionPresetSource->getDefaultPreset($dimensionName);
         if ($preset === NULL) {
             $preset = $defaultPreset;
         }
         if ($preset !== $defaultPreset) {
             $allDimensionPresetsAreDefault = FALSE;
         }
         if (!isset($preset['uriSegment'])) {
             throw new \Exception(sprintf('No "uriSegment" configured for content dimension preset "%s" for dimension "%s". Please check the content dimension configuration in Settings.yaml', $preset['identifier'], $dimensionName), 1395824520);
         }
         $uriSegment .= $preset['uriSegment'] . '_';
     }
     if ($allDimensionPresetsAreDefault && $currentNodeIsSiteNode) {
         return '/';
     } else {
         return ltrim(trim($uriSegment, '_') . '/', '/');
     }
 }
示例#2
0
 /**
  * @param array $dimensions Dimension values indexed by dimension name
  * @return array Allowed preset names for the given dimension combination indexed by dimension name
  */
 public function allowedPresetsByName(array $dimensions)
 {
     $allowedPresets = array();
     $preselectedDimensionPresets = array();
     foreach ($dimensions as $dimensionName => $dimensionValues) {
         $preset = $this->contentDimensionsPresetSource->findPresetByDimensionValues($dimensionName, $dimensionValues);
         if ($preset !== null) {
             $preselectedDimensionPresets[$dimensionName] = $preset['identifier'];
         }
     }
     foreach ($preselectedDimensionPresets as $dimensionName => $presetName) {
         $presets = $this->contentDimensionsPresetSource->getAllowedDimensionPresetsAccordingToPreselection($dimensionName, $preselectedDimensionPresets);
         $allowedPresets[$dimensionName] = array_keys($presets[$dimensionName]['presets']);
     }
     return $allowedPresets;
 }