$elements['#create_placeholder'
] = TRUE;
} // 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 isMethodCacheable() check when
// https://www.drupal.org/node/2367555 lands.
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.'
);
} $elements =
$this->placeholderGenerator->
createPlaceholder($elements);
} // Build the element if it is still empty.
if (isset($elements['#lazy_builder'
])) { $new_elements =
$this->
doCallback('#lazy_builder',
$elements['#lazy_builder'
][0
],
$elements['#lazy_builder'
][1
]);
// Throw an exception if #lazy_builder callback does not return an array;
// provide helpful details for troubleshooting.
assert(is_array($new_elements), "#lazy_builder callbacks must return a valid renderable array, got " .
gettype($new_elements) . " from " . Variable::
callableToString($elements['#lazy_builder'
][0
]));
// Retain the original cacheability metadata, plus cache keys.
CacheableMetadata::
createFromRenderArray($elements) ->
merge(CacheableMetadata::
createFromRenderArray($new_elements))