Neos\Neos\TypoScript\DimensionsMenuImplementation::buildItems PHP Метод

buildItems() защищенный Метод

Builds the array of Menu items for this variant menu
protected buildItems ( )
    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;
    }