assert(empty(array_diff(array_keys($elements),
$supported_keys)),
sprintf('When a #lazy_builder callback is specified, no properties can exist; all properties must be generated by the #lazy_builder callback. You specified the following properties: %s.',
implode(', ',
array_diff(array_keys($elements),
$supported_keys))));
} // Determine whether to do auto-placeholdering.
if ($this->placeholderGenerator->
canCreatePlaceholder($elements) &&
$this->placeholderGenerator->
shouldAutomaticallyPlaceholder($elements)) { $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
]));