// Early-return nothing if user does not have access.
if (isset($elements['#access'])) {
- // If #access is an AccessResultInterface object, we must apply it's
+ // If #access is an AccessResultInterface object, we must apply its
// cacheability metadata to the render array.
if ($elements['#access'] instanceof AccessResultInterface) {
$this->addCacheableDependency($elements, $elements['#access']);
if (count($elements['#lazy_builder']) !== 2) {
throw new \DomainException('The #lazy_builder property must have an array as a value, containing two values: the callback, and the arguments for the callback.');
}
- if (count($elements['#lazy_builder'][1]) !== count(array_filter($elements['#lazy_builder'][1], function($v) { return is_null($v) || is_scalar($v); }))) {
+ if (count($elements['#lazy_builder'][1]) !== count(array_filter($elements['#lazy_builder'][1], function ($v) {
+ return is_null($v) || is_scalar($v);
+ }))) {
throw new \DomainException("A #lazy_builder callback's context may only contain scalar values or NULL.");
}
$children = Element::children($elements);
// automatically by the Renderer. Adding them as though they are
// supported allows us to avoid throwing an exception 100% of the time.
'#weight',
- '#printed'
+ '#printed',
];
$unsupported_keys = array_diff(array_keys($elements), $supported_keys);
if (count($unsupported_keys)) {
// If instructed to create a placeholder, and a #lazy_builder callback is
// present (without such a callback, it would be impossible to replace the
// placeholder), replace the current element with a placeholder.
- // @todo remove the isMethodSafe() check when
+ // @todo remove the isMethodCacheable() check when
// https://www.drupal.org/node/2367555 lands.
- if (isset($elements['#create_placeholder']) && $elements['#create_placeholder'] === TRUE && $this->requestStack->getCurrentRequest()->isMethodSafe()) {
+ if (isset($elements['#create_placeholder']) && $elements['#create_placeholder'] === TRUE && $this->requestStack->getCurrentRequest()->isMethodCacheable()) {
if (!isset($elements['#lazy_builder'])) {
throw new \LogicException('When #create_placeholder is set, a #lazy_builder callback must be present as well.');
}
}
// All render elements support #markup and #plain_text.
- if (!empty($elements['#markup']) || !empty($elements['#plain_text'])) {
+ if (isset($elements['#markup']) || isset($elements['#plain_text'])) {
$elements = $this->ensureMarkupIsSafe($elements);
}
// We store the resulting output in $elements['#markup'], to be consistent
// with how render cached output gets stored. This ensures that placeholder
// replacement logic gets the same data to work with, no matter if #cache is
- // disabled, #cache is enabled, there is a cache hit or miss.
- $prefix = isset($elements['#prefix']) ? $this->xssFilterAdminIfUnsafe($elements['#prefix']) : '';
- $suffix = isset($elements['#suffix']) ? $this->xssFilterAdminIfUnsafe($elements['#suffix']) : '';
-
- $elements['#markup'] = Markup::create($prefix . $elements['#children'] . $suffix);
+ // disabled, #cache is enabled, there is a cache hit or miss. If
+ // #render_children is set the #prefix and #suffix will have already been
+ // added.
+ if (isset($elements['#render_children'])) {
+ $elements['#markup'] = Markup::create($elements['#children']);
+ }
+ else {
+ $prefix = isset($elements['#prefix']) ? $this->xssFilterAdminIfUnsafe($elements['#prefix']) : '';
+ $suffix = isset($elements['#suffix']) ? $this->xssFilterAdminIfUnsafe($elements['#suffix']) : '';
+ $elements['#markup'] = Markup::create($prefix . $elements['#children'] . $suffix);
+ }
// We've rendered this element (and its subtree!), now update the context.
$context->update($elements);
// being rendered: any code can add messages to render.
// This violates the principle that each lazy builder must be able to render
// itself in isolation, and therefore in any order. However, we cannot
- // change the way drupal_set_message() works in the Drupal 8 cycle. So we
- // have to accommodate its special needs.
+ // change the way \Drupal\Core\Messenger\Messenger works in the Drupal 8
+ // cycle. So we have to accommodate its special needs.
// Allowing placeholders to be rendered in a particular order (in this case:
// last) would violate this isolation principle. Thus a monopoly is granted
// to this one special case, with this hard-coded solution.
* @see \Drupal\Component\Utility\Xss::filterAdmin()
*/
protected function ensureMarkupIsSafe(array $elements) {
- if (empty($elements['#markup']) && empty($elements['#plain_text'])) {
- return $elements;
- }
-
- if (!empty($elements['#plain_text'])) {
+ if (isset($elements['#plain_text'])) {
$elements['#markup'] = Markup::create(Html::escape($elements['#plain_text']));
}
elseif (!($elements['#markup'] instanceof MarkupInterface)) {