You are here

public function Content::execute in JS Callback Handler 8.3

Executes the callback.

Parameters

mixed ...: Any number of arguments can be passed here.

Return value

mixed The content to return.

Overrides JsCallbackInterface::execute

File

src/Plugin/Js/Content.php, line 94

Class

Content
Plugin annotation @JsCallback( id = "js.content", allowed_methods = { "GET" }, csrf_token = FALSE, )

Namespace

Drupal\js\Plugin\Js

Code

public function execute($path = '') {

  // Normalize absolute URLs to an internal relative path.
  $base_url = \Drupal::service('router.request_context')
    ->getCompleteBaseUrl();
  if (!UrlHelper::isExternal($path) || UrlHelper::externalIsLocal($path, $base_url)) {
    $path = preg_replace('`^' . preg_quote($base_url) . '`', '', $path);
  }
  $request = $this
    ->getRequest($path);
  $controller = $this->controllerResolver
    ->getController($request);

  // Immediately return if there is no controller.
  if (!$controller) {
    throw new NotFoundHttpException();
  }

  // Set the title.
  if ($title = $this->titleResolver
    ->getTitle($request, $this
    ->getRoute($request))) {
    $this
      ->setTitle($title);
  }
  return call_user_func_array($controller, $this->controllerResolver
    ->getArguments($request, $controller));
}