You are here

protected function Renderer::doCallback in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::doCallback()
  2. 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 770

Class

Renderer
Turns a render array into an HTML string.

Namespace

Drupal\Core\Render

Code

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);
}