-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from dlubitz/Neos-4.3-and-5.x
Fusion based 404 handling
- Loading branch information
Showing
7 changed files
with
138 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace MOC\NotFound\Fusion\Eel\Helper; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Eel\ProtectedContextAwareInterface; | ||
|
||
class ContextHelper implements ProtectedContextAwareInterface | ||
{ | ||
/** | ||
* @Flow\InjectConfiguration(path="contentDimensions", package="Neos.ContentRepository") | ||
* @var array | ||
*/ | ||
protected $contentDimensionsConfiguration; | ||
|
||
/** | ||
* Returns a context array with matched dimension values per dimension for given request uri path. If nothing | ||
* matches, it returns a context array with default dimension values per dimension. | ||
* | ||
* @param $requestUriPath | ||
* @return array | ||
*/ | ||
public function ofRequestUriPath($requestUriPath) | ||
{ | ||
// No dimensions configured, context is empty | ||
if (count($this->contentDimensionsConfiguration) === 0) { | ||
return []; | ||
} | ||
|
||
$uriSegments = $this->getUriSegments($requestUriPath); | ||
$dimensionValues = $this->getDimensionValuesForUriSegments($uriSegments); | ||
if (empty($dimensionValues)) { | ||
$dimensionValues = $this->getDefaultDimensionValues(); | ||
} | ||
|
||
$targetDimensionValues = array_map(function ($dimensionValues) { | ||
return reset($dimensionValues); // Default target dimension value is first dimension value | ||
}, $dimensionValues); | ||
|
||
|
||
return [ | ||
'dimensions' => $dimensionValues, | ||
'targetDimensions' => $targetDimensionValues | ||
]; | ||
} | ||
|
||
/** | ||
* @param array $uriSegments | ||
* @return array | ||
*/ | ||
protected function getDimensionValuesForUriSegments($uriSegments) | ||
{ | ||
if (count($uriSegments) !== count($this->contentDimensionsConfiguration)) { | ||
return []; | ||
} | ||
|
||
$index = 0; | ||
$dimensionValues = []; | ||
foreach ($this->contentDimensionsConfiguration as $dimensionName => $dimensionConfiguration) { | ||
$uriSegment = $uriSegments[$index++]; | ||
foreach ($dimensionConfiguration['presets'] as $preset) { | ||
if ($uriSegment === $preset['uriSegment']) { | ||
$dimensionValues[$dimensionName] = $preset['values']; | ||
continue 2; | ||
} | ||
} | ||
} | ||
|
||
if (count($uriSegments) !== count($dimensionValues)) { | ||
return []; | ||
} | ||
|
||
return $dimensionValues; | ||
} | ||
|
||
/** | ||
* Returns default dimension values per dimension. | ||
* | ||
* @return array | ||
*/ | ||
protected function getDefaultDimensionValues() | ||
{ | ||
$dimensionValues = []; | ||
foreach ($this->contentDimensionsConfiguration as $dimensionName => $dimensionConfiguration) { | ||
$dimensionValues[$dimensionName] = [$dimensionConfiguration['default']]; | ||
} | ||
return $dimensionValues; | ||
} | ||
|
||
protected function getUriSegments($requestUriPath) | ||
{ | ||
$pathParts = explode('/', trim($requestUriPath, '/'), 2); | ||
return explode('_', $pathParts[0]); | ||
} | ||
|
||
public function allowsCallOfMethod($methodName) | ||
{ | ||
return true; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
Neos: | ||
Flow: | ||
error: | ||
exceptionHandler: | ||
renderingGroups: | ||
notFoundExceptions: | ||
matchingStatusCodes: [ 404, 410 ] | ||
options: | ||
viewClassName: Neos\FluidAdaptor\View\TemplateView | ||
templatePathAndFilename: 'resource://MOC.NotFound/Private/Templates/404.html' | ||
variables: | ||
path: '404.html' # skip suffix if unset | ||
Fusion: | ||
defaultContext: | ||
NotFound.Context: MOC\NotFound\Fusion\Eel\Helper\ContextHelper | ||
Neos: | ||
fusion: | ||
autoInclude: | ||
MOC.NotFound: true | ||
MOC: | ||
NotFound: | ||
uriPathSegment: 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
prototype(MOC.NotFound:NotFoundDocument) < prototype(Neos.Fusion:Value) { | ||
uriPathSegment = ${Configuration.setting('MOC.NotFound.uriPathSegment')} | ||
context = ${NotFound.Context.ofRequestUriPath(this.requestUriPath)} | ||
|
||
value = ${q(site).context(this.context).children('[instanceof Neos.Neos:Document]').filter('[uriPathSegment="' + this.uriPathSegment + '"]').get(0)} | ||
} | ||
|
||
error { | ||
@context.notfoundDocument = MOC.NotFound:NotFoundDocument { | ||
requestUriPath = ${request.httpRequest.uri.path} | ||
} | ||
|
||
4xx { | ||
@position = 'start' | ||
condition = ${statusCode >= 400 && statusCode < 500 && notfoundDocument} | ||
renderer = Neos.Fusion:Renderer { | ||
@context.node = ${notfoundDocument} | ||
@context.documentNode = ${notfoundDocument} | ||
renderPath = '/root' | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
} | ||
], | ||
"require": { | ||
"neos/neos": ">3.3" | ||
"neos/neos": ">=4.3" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
|