@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $dimensionValues = $this->getDefaultDimensionValues(); |
34 | 34 | } |
35 | 35 | |
36 | - $targetDimensionValues = array_map(function ($dimensionValues) { |
|
36 | + $targetDimensionValues = array_map(function($dimensionValues) { |
|
37 | 37 | return reset($dimensionValues); // Default target dimension value is first dimension value |
38 | 38 | }, $dimensionValues); |
39 | 39 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | { |
83 | 83 | $dimensionValues = []; |
84 | 84 | foreach ($this->contentDimensionsConfiguration as $dimensionName => $dimensionConfiguration) { |
85 | - $dimensionValues[$dimensionName] = [$dimensionConfiguration['default']]; |
|
85 | + $dimensionValues[$dimensionName] = [$dimensionConfiguration['default']]; |
|
86 | 86 | } |
87 | 87 | return $dimensionValues; |
88 | 88 | } |
@@ -7,94 +7,94 @@ |
||
7 | 7 | |
8 | 8 | class ContextHelper implements ProtectedContextAwareInterface |
9 | 9 | { |
10 | - /** |
|
11 | - * @Flow\InjectConfiguration(path="contentDimensions", package="Neos.ContentRepository") |
|
12 | - * @var array |
|
13 | - */ |
|
14 | - protected $contentDimensionsConfiguration; |
|
10 | + /** |
|
11 | + * @Flow\InjectConfiguration(path="contentDimensions", package="Neos.ContentRepository") |
|
12 | + * @var array |
|
13 | + */ |
|
14 | + protected $contentDimensionsConfiguration; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Returns a context array with matched dimension values per dimension for given request uri path. If nothing |
|
18 | - * matches, it returns a context array with default dimension values per dimension. |
|
19 | - * |
|
20 | - * @param $requestUriPath |
|
21 | - * @return array |
|
22 | - */ |
|
23 | - public function ofRequestUriPath($requestUriPath) |
|
24 | - { |
|
25 | - // No dimensions configured, context is empty |
|
26 | - if (count($this->contentDimensionsConfiguration) === 0) { |
|
27 | - return []; |
|
28 | - } |
|
16 | + /** |
|
17 | + * Returns a context array with matched dimension values per dimension for given request uri path. If nothing |
|
18 | + * matches, it returns a context array with default dimension values per dimension. |
|
19 | + * |
|
20 | + * @param $requestUriPath |
|
21 | + * @return array |
|
22 | + */ |
|
23 | + public function ofRequestUriPath($requestUriPath) |
|
24 | + { |
|
25 | + // No dimensions configured, context is empty |
|
26 | + if (count($this->contentDimensionsConfiguration) === 0) { |
|
27 | + return []; |
|
28 | + } |
|
29 | 29 | |
30 | - $uriSegments = $this->getUriSegments($requestUriPath); |
|
31 | - $dimensionValues = $this->getDimensionValuesForUriSegments($uriSegments); |
|
32 | - if (empty($dimensionValues)) { |
|
33 | - $dimensionValues = $this->getDefaultDimensionValues(); |
|
34 | - } |
|
30 | + $uriSegments = $this->getUriSegments($requestUriPath); |
|
31 | + $dimensionValues = $this->getDimensionValuesForUriSegments($uriSegments); |
|
32 | + if (empty($dimensionValues)) { |
|
33 | + $dimensionValues = $this->getDefaultDimensionValues(); |
|
34 | + } |
|
35 | 35 | |
36 | - $targetDimensionValues = array_map(function ($dimensionValues) { |
|
37 | - return reset($dimensionValues); // Default target dimension value is first dimension value |
|
38 | - }, $dimensionValues); |
|
36 | + $targetDimensionValues = array_map(function ($dimensionValues) { |
|
37 | + return reset($dimensionValues); // Default target dimension value is first dimension value |
|
38 | + }, $dimensionValues); |
|
39 | 39 | |
40 | 40 | |
41 | - return [ |
|
42 | - 'dimensions' => $dimensionValues, |
|
43 | - 'targetDimensions' => $targetDimensionValues |
|
44 | - ]; |
|
45 | - } |
|
41 | + return [ |
|
42 | + 'dimensions' => $dimensionValues, |
|
43 | + 'targetDimensions' => $targetDimensionValues |
|
44 | + ]; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param array $uriSegments |
|
49 | - * @return array |
|
50 | - */ |
|
51 | - protected function getDimensionValuesForUriSegments($uriSegments) |
|
52 | - { |
|
53 | - if (count($uriSegments) !== count($this->contentDimensionsConfiguration)) { |
|
54 | - return []; |
|
55 | - } |
|
47 | + /** |
|
48 | + * @param array $uriSegments |
|
49 | + * @return array |
|
50 | + */ |
|
51 | + protected function getDimensionValuesForUriSegments($uriSegments) |
|
52 | + { |
|
53 | + if (count($uriSegments) !== count($this->contentDimensionsConfiguration)) { |
|
54 | + return []; |
|
55 | + } |
|
56 | 56 | |
57 | - $index = 0; |
|
58 | - $dimensionValues = []; |
|
59 | - foreach ($this->contentDimensionsConfiguration as $dimensionName => $dimensionConfiguration) { |
|
60 | - $uriSegment = $uriSegments[$index++]; |
|
61 | - foreach ($dimensionConfiguration['presets'] as $preset) { |
|
62 | - if ($uriSegment === $preset['uriSegment']) { |
|
63 | - $dimensionValues[$dimensionName] = $preset['values']; |
|
64 | - continue 2; |
|
65 | - } |
|
66 | - } |
|
67 | - } |
|
57 | + $index = 0; |
|
58 | + $dimensionValues = []; |
|
59 | + foreach ($this->contentDimensionsConfiguration as $dimensionName => $dimensionConfiguration) { |
|
60 | + $uriSegment = $uriSegments[$index++]; |
|
61 | + foreach ($dimensionConfiguration['presets'] as $preset) { |
|
62 | + if ($uriSegment === $preset['uriSegment']) { |
|
63 | + $dimensionValues[$dimensionName] = $preset['values']; |
|
64 | + continue 2; |
|
65 | + } |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | - if (count($uriSegments) !== count($dimensionValues)) { |
|
70 | - return []; |
|
71 | - } |
|
69 | + if (count($uriSegments) !== count($dimensionValues)) { |
|
70 | + return []; |
|
71 | + } |
|
72 | 72 | |
73 | - return $dimensionValues; |
|
74 | - } |
|
73 | + return $dimensionValues; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Returns default dimension values per dimension. |
|
78 | - * |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - protected function getDefaultDimensionValues() |
|
82 | - { |
|
83 | - $dimensionValues = []; |
|
84 | - foreach ($this->contentDimensionsConfiguration as $dimensionName => $dimensionConfiguration) { |
|
85 | - $dimensionValues[$dimensionName] = [$dimensionConfiguration['default']]; |
|
86 | - } |
|
87 | - return $dimensionValues; |
|
88 | - } |
|
76 | + /** |
|
77 | + * Returns default dimension values per dimension. |
|
78 | + * |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + protected function getDefaultDimensionValues() |
|
82 | + { |
|
83 | + $dimensionValues = []; |
|
84 | + foreach ($this->contentDimensionsConfiguration as $dimensionName => $dimensionConfiguration) { |
|
85 | + $dimensionValues[$dimensionName] = [$dimensionConfiguration['default']]; |
|
86 | + } |
|
87 | + return $dimensionValues; |
|
88 | + } |
|
89 | 89 | |
90 | - protected function getUriSegments($requestUriPath) |
|
91 | - { |
|
92 | - $pathParts = explode('/', trim($requestUriPath, '/'), 2); |
|
93 | - return explode('_', $pathParts[0]); |
|
94 | - } |
|
90 | + protected function getUriSegments($requestUriPath) |
|
91 | + { |
|
92 | + $pathParts = explode('/', trim($requestUriPath, '/'), 2); |
|
93 | + return explode('_', $pathParts[0]); |
|
94 | + } |
|
95 | 95 | |
96 | - public function allowsCallOfMethod($methodName) |
|
97 | - { |
|
98 | - return true; |
|
99 | - } |
|
96 | + public function allowsCallOfMethod($methodName) |
|
97 | + { |
|
98 | + return true; |
|
99 | + } |
|
100 | 100 | } |
@@ -17,43 +17,43 @@ |
||
17 | 17 | */ |
18 | 18 | class LocaleHelper implements ProtectedContextAwareInterface |
19 | 19 | { |
20 | - /** |
|
21 | - * @Flow\Inject |
|
22 | - * @var Service |
|
23 | - */ |
|
24 | - protected $i18nService; |
|
20 | + /** |
|
21 | + * @Flow\Inject |
|
22 | + * @var Service |
|
23 | + */ |
|
24 | + protected $i18nService; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Given a node this tries to set the current locale for the Flow i18n service |
|
28 | - * from the content dimension "language", if possible. |
|
29 | - * |
|
30 | - * The input node is returned as is for chaining, to make sure the operation is |
|
31 | - * actually evaluated. |
|
32 | - * |
|
33 | - * @param NodeInterface $node |
|
34 | - * @return NodeInterface |
|
35 | - * @throws \Neos\Flow\I18n\Exception\InvalidLocaleIdentifierException |
|
36 | - */ |
|
37 | - public function setCurrentFromNode(NodeInterface $node, string $languageDimensionName): NodeInterface |
|
38 | - { |
|
39 | - $dimensions = $node->getContext()->getDimensions(); |
|
40 | - if (array_key_exists($languageDimensionName, $dimensions) && $dimensions[$languageDimensionName] !== []) { |
|
41 | - $currentLocale = new Locale($dimensions[$languageDimensionName][0]); |
|
42 | - $this->i18nService->getConfiguration()->setCurrentLocale($currentLocale); |
|
43 | - $this->i18nService->getConfiguration()->setFallbackRule(['strict' => false, 'order' => array_reverse($dimensions[$languageDimensionName])]); |
|
44 | - } |
|
26 | + /** |
|
27 | + * Given a node this tries to set the current locale for the Flow i18n service |
|
28 | + * from the content dimension "language", if possible. |
|
29 | + * |
|
30 | + * The input node is returned as is for chaining, to make sure the operation is |
|
31 | + * actually evaluated. |
|
32 | + * |
|
33 | + * @param NodeInterface $node |
|
34 | + * @return NodeInterface |
|
35 | + * @throws \Neos\Flow\I18n\Exception\InvalidLocaleIdentifierException |
|
36 | + */ |
|
37 | + public function setCurrentFromNode(NodeInterface $node, string $languageDimensionName): NodeInterface |
|
38 | + { |
|
39 | + $dimensions = $node->getContext()->getDimensions(); |
|
40 | + if (array_key_exists($languageDimensionName, $dimensions) && $dimensions[$languageDimensionName] !== []) { |
|
41 | + $currentLocale = new Locale($dimensions[$languageDimensionName][0]); |
|
42 | + $this->i18nService->getConfiguration()->setCurrentLocale($currentLocale); |
|
43 | + $this->i18nService->getConfiguration()->setFallbackRule(['strict' => false, 'order' => array_reverse($dimensions[$languageDimensionName])]); |
|
44 | + } |
|
45 | 45 | |
46 | - return $node; |
|
47 | - } |
|
46 | + return $node; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * All methods are considered safe |
|
51 | - * |
|
52 | - * @param string $methodName |
|
53 | - * @return boolean |
|
54 | - */ |
|
55 | - public function allowsCallOfMethod($methodName) |
|
56 | - { |
|
57 | - return true; |
|
58 | - } |
|
49 | + /** |
|
50 | + * All methods are considered safe |
|
51 | + * |
|
52 | + * @param string $methodName |
|
53 | + * @return boolean |
|
54 | + */ |
|
55 | + public function allowsCallOfMethod($methodName) |
|
56 | + { |
|
57 | + return true; |
|
58 | + } |
|
59 | 59 | } |