function Renderer::doCallback

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::doCallback()
  2. 8.9.x core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::doCallback()
  3. 10 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 817

Class

Renderer
Turns a render array into an HTML string.

Namespace

Drupal\Core\Render

Code

protected function doCallback($callback_type, $callback, array $args) {
    $callable = $this->callableResolver
        ->getCallableFromDefinition($callback);
    $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($callable, $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.