Neos\Neos\Domain\Service\ContentDimensionPresetSourceInterface::findPresetByUriSegment PHP Method

findPresetByUriSegment() public method

Find a dimension preset by URI identifier
public findPresetByUriSegment ( string $dimensionName, string $uriSegment ) : array
$dimensionName string The dimension name where the preset should be searched
$uriSegment string The URI segment for a Content Dimension Preset
return array The preset configuration, including the identifier as key "identifier" or NULL if none was found
    public function findPresetByUriSegment($dimensionName, $uriSegment);

Usage Example

 /**
  * Parses the given request path and checks if the first path segment is one or a set of content dimension preset
  * identifiers. If that is the case, the return value is an array of dimension names and their preset URI segments.
  * Doesn't allow empty uriSegment, but allows uriSegment to be not unique across presets.
  *
  * If the first path segment contained content dimension information, it is removed from &$requestPath.
  *
  * @param string &$requestPath The request path currently being processed by this route part handler, e.g. "de_global/startseite/ueber-uns"
  * @return array An array of dimension name => dimension values (array of string)
  * @throws InvalidDimensionPresetCombinationException
  * @throws InvalidRequestPathException
  * @throws NoSuchDimensionValueException
  */
 protected function parseDimensionsAndNodePathFromRequestPathAllowingNonUniqueSegment(&$requestPath)
 {
     $dimensionPresets = $this->contentDimensionPresetSource->getAllPresets();
     if (count($dimensionPresets) === 0) {
         return [];
     }
     $dimensionsAndDimensionValues = [];
     $chosenDimensionPresets = [];
     $matches = [];
     preg_match(self::DIMENSION_REQUEST_PATH_MATCHER, $requestPath, $matches);
     if (!isset($matches['firstUriPart'])) {
         foreach ($dimensionPresets as $dimensionName => $dimensionPreset) {
             $dimensionsAndDimensionValues[$dimensionName] = $dimensionPreset['presets'][$dimensionPreset['defaultPreset']]['values'];
             $chosenDimensionPresets[$dimensionName] = $dimensionPreset['defaultPreset'];
         }
     } else {
         $firstUriPart = explode('_', $matches['firstUriPart']);
         if (count($firstUriPart) !== count($dimensionPresets)) {
             throw new InvalidRequestPathException(sprintf('The first path segment of the request URI (%s) does not contain the necessary content dimension preset identifiers for all configured dimensions. This might be an old URI which doesn\'t match the current dimension configuration anymore.', $requestPath), 1413389121);
         }
         foreach ($dimensionPresets as $dimensionName => $dimensionPreset) {
             $uriSegment = array_shift($firstUriPart);
             $preset = $this->contentDimensionPresetSource->findPresetByUriSegment($dimensionName, $uriSegment);
             if ($preset === null) {
                 throw new NoSuchDimensionValueException(sprintf('Could not find a preset for content dimension "%s" through the given URI segment "%s".', $dimensionName, $uriSegment), 1413389321);
             }
             $dimensionsAndDimensionValues[$dimensionName] = $preset['values'];
             $chosenDimensionPresets[$dimensionName] = $preset['identifier'];
         }
         $requestPath = isset($matches['remainingRequestPath']) ? $matches['remainingRequestPath'] : '';
     }
     if (!$this->contentDimensionPresetSource->isPresetCombinationAllowedByConstraints($chosenDimensionPresets)) {
         throw new InvalidDimensionPresetCombinationException(sprintf('The resolved content dimension preset combination (%s) is invalid or restricted by content dimension constraints. Check your content dimension settings if you think that this is an error.', implode(', ', array_keys($chosenDimensionPresets))), 1462175794805);
     }
     return $dimensionsAndDimensionValues;
 }
ContentDimensionPresetSourceInterface