function Renderer::doCallback
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::doCallback()
- 10 core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::doCallback()
- 11.x core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::doCallback()
Performs a callback.
Parameters
string $callback_type: The type of the callback. For example, '#post_render'.
string|callable $callback: The callback to perform.
array $args: The arguments to pass to the callback.
Return value
mixed The callback's return value.
See also
\Drupal\Core\Security\TrustedCallbackInterface
1 call to Renderer::doCallback()
- Renderer::doRender in core/
lib/ Drupal/ Core/ Render/ Renderer.php - See the docs for ::render().
File
-
core/
lib/ Drupal/ Core/ Render/ Renderer.php, line 772
Class
- Renderer
- Turns a render array into an HTML string.
Namespace
Drupal\Core\RenderCode
protected function doCallback($callback_type, $callback, array $args) {
if (is_string($callback)) {
$double_colon = strpos($callback, '::');
if ($double_colon === FALSE) {
$callback = $this->controllerResolver
->getControllerFromDefinition($callback);
}
elseif ($double_colon > 0) {
$callback = explode('::', $callback, 2);
}
}
$message = sprintf('Render %s callbacks must be methods of a class that implements \\Drupal\\Core\\Security\\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', $callback_type, '%s');
// Add \Drupal\Core\Render\Element\RenderCallbackInterface as an extra
// trusted interface so that:
// - All public methods on Render elements are considered trusted.
// - Helper classes that contain only callback methods can implement this
// instead of TrustedCallbackInterface.
return $this->doTrustedCallback($callback, $args, $message, TrustedCallbackInterface::THROW_EXCEPTION, RenderCallbackInterface::class);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.