Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Added custom layout support in NotFoundDelegate #511

Merged
merged 5 commits into from
Oct 9, 2017

Conversation

mano87
Copy link

@mano87 mano87 commented Sep 15, 2017

This is a better implementation for chaning the layout of error pages. See also the issue: #360

I hope my pull request will be accepted :-)

Copy link
Member

@geerteltink geerteltink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: I don't use zend-view myself, so I have no idea how its layout system works.

Shouldn't this be added somehow to zend-expressive-zendviewrenderer, as it's specific for zend-view only? No idea how that woud work though. If it isn't possible add a zendviewrenderer specific NotFoundDelegate in that package?

$response = $this->responsePrototype->withStatus(StatusCodeInterface::STATUS_NOT_FOUND);
$response->getBody()->write(
$this->renderer->render($this->template, ['request' => $request])
$this->renderer->render($this->template, $templateData)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add a new variable?

$this->renderer->render($this->template, [
    'request'  => $request,
    'layout'  => $this->layout,
]);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will rework this point to make the parameter optional - or do you have a better idea? Another option would be that in the factory other optional parameters can be passed to the renderer no matter what...

@@ -58,7 +67,7 @@ public function __construct(
*/
public function process(ServerRequestInterface $request)
{
if (! $this->renderer) {
if (!$this->renderer) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change please. CS is now failing:

There must be a single space after a NOT operator; 0 found

@@ -78,7 +87,7 @@ private function generatePlainTextResponse(ServerRequestInterface $request)
->write(sprintf(
'Cannot %s %s',
$request->getMethod(),
(string) $request->getUri()
(string)$request->getUri()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change please. We don;t have currently sniff to check it, so all seems to be fine, but for consistency we should have here single space.

$renderer->render(NotFoundDelegate::TEMPLATE_DEFAULT, [
'request' => $request,
'layout' => NotFoundDelegate::LAYOUT_DEFAULT
])->willReturn('CONTENT');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last line should have one less indent:

        $renderer->render(NotFoundDelegate::TEMPLATE_DEFAULT, [
            'request' => $request,
            'layout' => NotFoundDelegate::LAYOUT_DEFAULT
        ])->willReturn('CONTENT');

->willReturn('CONTENT');
$renderer->render(NotFoundDelegate::TEMPLATE_DEFAULT, [
'request' => $request,
'layout' => NotFoundDelegate::LAYOUT_DEFAULT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add trailing comma after last element in the array

@weierophinney weierophinney added this to the 2.1.0 milestone Oct 9, 2017
Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor change necessary to make this backwards compatible; I'll make that change, and the other CS changes, on merge.

Thanks, @mano87

@@ -16,6 +16,7 @@
class NotFoundDelegate implements DelegateInterface
{
const TEMPLATE_DEFAULT = 'error::404';
const LAYOUT_DEFAULT = 'layout::error';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main problem I have with this is that we do not at this time define a layout::error template in the skeleton application, only a layout::default. As such, I think that should likely be the default in this situation, to allow for backwards compatibility with existing applications.

@weierophinney weierophinney merged commit 697e597 into zendframework:develop Oct 9, 2017
weierophinney added a commit that referenced this pull request Oct 9, 2017
Added custom layout support in NotFoundDelegate
weierophinney added a commit that referenced this pull request Oct 9, 2017
weierophinney added a commit that referenced this pull request Oct 9, 2017
weierophinney added a commit that referenced this pull request Oct 9, 2017
@weierophinney
Copy link
Member

Thanks, @mano87

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants