Skip to content

Commit

Permalink
TASK: Also adjust dnymaically loaded language constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellienert committed Mar 18, 2021
1 parent 9ae830d commit b93da28
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 34 deletions.
40 changes: 8 additions & 32 deletions Classes/Eel/SiteSpecificContentDimensionsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,16 @@

class SiteSpecificContentDimensionsHelper implements ProtectedContextAwareInterface
{

/**
* @Flow\InjectConfiguration(package="PunktDe.SiteSpecifics")
* @var array
*/
protected $settings;

/**
* @Flow\Inject
* @var ContentDimensionPresetSourceInterface
*/
protected $contentDimensionsPresetSource;

/**
* @var ConfigurationContentDimensionPresetSource
*/
protected $alteredContentDimensionsPresetSource;

public function contentDimensionsByNameForSite(NodeInterface $site): array
{
return $this->getAlteredPresetSource($site)->getAllPresets();
$this->alteredPresetSource($site);
return $this->contentDimensionsPresetSource->getAllPresets();
}

/**
Expand All @@ -49,39 +38,26 @@ public function contentDimensionsByNameForSite(NodeInterface $site): array
*/
public function allowedPresetsByNameForSite(array $dimensions, NodeInterface $site): array
{
$this->alteredPresetSource($site);

$allowedPresets = [];
$preselectedDimensionPresets = [];
foreach ($dimensions as $dimensionName => $dimensionValues) {
$preset = $this->getAlteredPresetSource($site)->findPresetByDimensionValues($dimensionName, $dimensionValues);
$preset = $this->contentDimensionsPresetSource->findPresetByDimensionValues($dimensionName, $dimensionValues);
if ($preset !== null) {
$preselectedDimensionPresets[$dimensionName] = $preset['identifier'];
}
}
foreach ($preselectedDimensionPresets as $dimensionName => $presetName) {
$presets = $this->getAlteredPresetSource($site)->getAllowedDimensionPresetsAccordingToPreselection($dimensionName, $preselectedDimensionPresets);
$presets = $this->contentDimensionsPresetSource->getAllowedDimensionPresetsAccordingToPreselection($dimensionName, $preselectedDimensionPresets);
$allowedPresets[$dimensionName] = array_keys($presets[$dimensionName]['presets']);
}
return $allowedPresets;
}

protected function getAlteredPresetSource(NodeInterface $site): ContentDimensionPresetSourceInterface
protected function alteredPresetSource(NodeInterface $site): void
{
if ($this->alteredContentDimensionsPresetSource instanceof ContentDimensionPresetSourceInterface) {
return $this->alteredContentDimensionsPresetSource;
}

if($this->contentDimensionsPresetSource instanceof DependencyProxy) {
$this->contentDimensionsPresetSource->_activateDependency();
}

$this->alteredContentDimensionsPresetSource = clone $this->contentDimensionsPresetSource;
$originalConfiguration = ObjectAccess::getProperty($this->contentDimensionsPresetSource, 'configuration', true);

$dimensionSelectorOverride = $this->settings[$site->getContext()->getCurrentSite()->getName()]['dimensionSelector'] ?? null;
$alteredConfiguration = DimensionCombinationService::adjustDimensionCombinations($originalConfiguration, $dimensionSelectorOverride);
$this->alteredContentDimensionsPresetSource->setConfiguration($alteredConfiguration);

return $this->alteredContentDimensionsPresetSource;
$this->contentDimensionsPresetSource->alterPresetSourceForSite($site->getContext()->getCurrentSite()->getName());
}


Expand Down
14 changes: 14 additions & 0 deletions Classes/Service/SiteDeterminationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,24 @@ public function getCurrentSiteName(): ?string

$httpRequest = ServerRequest::fromGlobals();

/*
* Site as query parameter.
* Used when querying adjusted nodeTypes
*/
if (array_key_exists('site', $httpRequest->getQueryParams())) {
self::$siteName = $httpRequest->getQueryParams()['site'] ?? '';
}

/*
* Site as uri path segment
* Used to get dimension constraints in the backend
*/
preg_match('/content-dimensions\/(\S+)\/country\.json/', $httpRequest->getUri()->getPath(), $matches, PREG_OFFSET_CAPTURE);
if (($matches[1] ?? null) !== null) {
self::$siteName = $matches[1][0];
return self::$siteName;
}

return self::$siteName;
}
}
58 changes: 58 additions & 0 deletions Classes/Service/SiteSpecificContentDimensionPresetSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);

namespace PunktDe\SiteSpecifics\Service;

/*
* (c) 2021 punkt.de GmbH - Karlsruhe, Germany - http://punkt.de
* All rights reserved.
*/

use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Service\ConfigurationContentDimensionPresetSource;

/**
* @Flow\Scope("singleton")
*/
class SiteSpecificContentDimensionPresetSource extends ConfigurationContentDimensionPresetSource
{

/**
* @Flow\Inject
* @var SiteDeterminationService
*/
protected $siteDeterminationService;

/**
* @Flow\InjectConfiguration(package="PunktDe.SiteSpecifics")
* @var array
*/
protected $settings;

protected bool $configurationAdjusted = false;

public function initializeObject(): void
{
$siteName = $this->siteDeterminationService->getCurrentSiteName();

if ($siteName !== null) {
$this->alterPresetSourceForSite($siteName);
}
}

public function alterPresetSourceForSite(string $siteName): void
{
if ($this->configurationAdjusted) {
return;
}

$dimensionSelectorOverride = $this->settings[$siteName]['dimensionSelector'] ?? null;

if ($dimensionSelectorOverride === null) {
return;
}

$this->configuration = DimensionCombinationService::adjustDimensionCombinations($this->configuration, $dimensionSelectorOverride);
$this->configurationAdjusted = true;
}
}
10 changes: 10 additions & 0 deletions Configuration/Objects.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'Neos\ContentRepository\Domain\Service\ContentDimensionPresetSourceInterface':
className: PunktDe\SiteSpecifics\Service\SiteSpecificContentDimensionPresetSource

'Neos\Neos\Domain\Service\ContentDimensionPresetSourceInterface':
className: PunktDe\SiteSpecifics\Service\SiteSpecificContentDimensionPresetSource

PunktDe\SiteSpecifics\Service\SiteSpecificContentDimensionPresetSource:
properties:
configuration:
setting: Neos.ContentRepository.contentDimensions
22 changes: 22 additions & 0 deletions Configuration/Routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-
name: 'Services - ContentDimensionController->index() with site'
uriPattern: 'content-dimensions/{site}'
defaults:
'@package': 'Neos.Neos'
'@controller': 'Service\ContentDimensions'
'@action': 'index'
site: ''
appendExceedingArguments: true
httpMethods: ['GET']

-
name: 'Services - ContentDimensionController->show() with site'
uriPattern: 'content-dimensions/{site}/{dimensionName}(.{@format})'
defaults:
'@package': 'Neos.Neos'
'@controller': 'Service\ContentDimensions'
'@action': 'show'
'@format': 'html'
site: ''
appendExceedingArguments: true
httpMethods: ['GET']
6 changes: 6 additions & 0 deletions Configuration/Settings.Neos.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
Neos:
Flow:
mvc:
routes:
'PunktDe.SiteSpecifics':
position: 'before Neos.Neos'

Neos:
Ui:
configurationDefaultEelContext:
Expand Down
8 changes: 6 additions & 2 deletions Resources/Private/Fusion/Override/Neos.Neos.Ui/Root.fusion
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
backend.configuration.endpoints.nodeTypeSchema.arguments.site = ${site.context.currentSite.name}
backend.configuration.endpoints.nodeTypeSchema.arguments.version.@process.addsite = ${value + '_' + String.md5(site.context.currentSite.name)}
backend {
configuration.endpoints.nodeTypeSchema.arguments.site = ${site.context.currentSite.name}
configuration.endpoints.nodeTypeSchema.arguments.version.@process.addsite = ${value + '_' + String.md5(site.context.currentSite.name)}

routes.core.service.contentDimensions.arguments.site = ${site.context.currentSite.name}
}

0 comments on commit b93da28

Please sign in to comment.