Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291711

Make LayoutInterface not require rendering a layout, but only building the render array

$
0
0

Note: There is no component for layout.module, so I'm using base system.

Issue description

\Drupal\layout\Plugin\LayoutInterface::renderLayout() builds a render array and then directly renders it using drupal_render(). This makes altering the render array impossible for sub-classes or callers. Additonally, most places where layouts might be used, such as route controllers support returning render arrays anywhere, so the rendering is unnecessary. This can be seen on the layout demo page, where layout.admin.inc does array('#markup' => $layout->renderLayout());

Proposed resolution

Rename LayoutInterface::renderLayout() into LayoutInterface::buildLayout() and make it return the render array.

Notes

This patch contains a couple changes that are technically unrelated, but were in the context of the patch anyway, and it's so small, so...
- Change the parameter order of renderLayout()/buildLayout() from $admin, $regions to $regions, $admin. IMO that's much more natural.
- StaticLayout contains some public methods that are not on LayoutInterface and are only called from within renderLayout()/buildLayout(). This patch changes them to protected.

Previous report

Problem

\Drupal\layout\Plugin\Layout\StaticLayout::renderLayout() builds up a render array representing the layout and then calls drupal_render on it.

If one wants to alter the behavior of this class there is no way to hook in when the render array has been built before it gets rendered.

Proposed resolution

Add a protected buildLayout() method which just builds the render array. renderLayout() then calls that and calls drupal_render() on the return. Sub-classes can then override buildLayout(), call parent::buildLayout() and alter to their liking.


Viewing all articles
Browse latest Browse all 291711

Trending Articles