Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: (Neos.Neos) Restore show action of ContentDimensionsController #4395

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

namespace Neos\Neos\Controller\Service;

use Neos\ContentRepository\Core\DimensionSpace\ContentDimensionZookeeper;
use Neos\ContentRepository\Core\Dimension\ContentDimensionId;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ActionController;
Expand Down Expand Up @@ -76,4 +77,73 @@ public function indexAction()
);
}
}

/**
* Returns only presets of the dimension specified by $dimensionName. But even though only one dimension is returned,
* the output follows the structure as described in ContentDimensionPresetSourceInterface::getAllPresets().
ahaeslich marked this conversation as resolved.
Show resolved Hide resolved
*
* It is possible to pass a selection of presets as a filter. In that case, $chosenDimensionPresets must be an array
* of one or more dimension names (key) and preset names (value). The returned list will then only contain dimension
* presets which are allowed in combination with the given presets.
*
* Example: Given that $chosenDimensionPresets = array('country' => 'US') and that a second dimension "language"
* exists and $dimensionName is "language. This method will now display a list of dimension presets for the dimension
* "language" which are allowed in combination with the country "US".
*
* @param string $dimensionName Name of the dimension to return presets for
* @param array $chosenDimensionPresets An optional array of dimension names and a single preset per dimension
* @phpstan-param array<string,string> $chosenDimensionPresets
* @return void
*/
public function showAction($dimensionName, $chosenDimensionPresets = []): void
{
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())
->contentRepositoryId;
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);

$contentDimensionSource = $contentRepository->getContentDimensionSource();

$contentDimensionId = new ContentDimensionId($dimensionName);
$contentDimension = $contentDimensionSource->getDimension($contentDimensionId);
if (is_null($contentDimension)) {
$this->throwStatus(404, sprintf('The dimension %s does not exist.', $dimensionName));
}

$interDimensionalVariationGraph = $contentRepository->getVariationGraph();
$allowedSubSpace = $interDimensionalVariationGraph->getDimensionSpacePoints();

$selectedDimensionSpacepoint = DimensionSpacePoint::fromArray($chosenDimensionPresets);
$allowedDimensionValues = [];
foreach ($contentDimension->values as $contentDimensionValue) {
$probeDimensionSpacepoint = $selectedDimensionSpacepoint->vary(
$contentDimensionId,
$contentDimensionValue->value
);

if ($allowedSubSpace->contains($probeDimensionSpacepoint)) {
$allowedDimensionValues[] = $contentDimensionValue;
}
}

// Build Legacy Response Shape
$contentDimensionsAndPresets = [
$contentDimensionId->value => [
'label' => $contentDimension->getConfigurationValue('label'),
'icon' => $contentDimension->getConfigurationValue('icon'),
'presets' => []
]
];
foreach ($allowedDimensionValues as $allowedDimensionValue) {
$contentDimensionsAndPresets[$contentDimensionId->value]['presets'][$allowedDimensionValue->value] = [
'label' => $allowedDimensionValue->getConfigurationValue('label')
];
}

if ($this->view instanceof JsonView) {
$this->view->assign('value', $contentDimensionsAndPresets);
} else {
$this->view->assign('dimensionName', $dimensionName);
$this->view->assign('contentDimensionsPresets', $contentDimensionsAndPresets);
}
}
}
11 changes: 11 additions & 0 deletions Neos.Neos/Configuration/Routes.Service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,14 @@
'@action': 'index'
appendExceedingArguments: true
httpMethods: ['GET']

-
name: 'Services - ContentDimensionController->show()'
uriPattern: 'content-dimensions/{dimensionName}(.{@format})'
defaults:
'@package': 'Neos.Neos'
'@controller': 'Service\ContentDimensions'
'@action': 'show'
'@format': 'html'
appendExceedingArguments: true
httpMethods: ['GET']