You are here

public function Js::getJsParameter in JS Callback Handler 8.3

Retrieves parameter from current request prefixed with "js" and removes it.

Parameters

string $name: The name of the parameter to retrieve, minus any "js" or "js_" prefix.

mixed $default: The default value to return if parameter does not exist.

bool $remove: Flag indicating whether parameter should be removed from the request.

Return value

string|null The parameter value or the default value.

2 calls to Js::getJsParameter()
Js::execute in src/Js.php
Executes the requested JS Callback.
Js::getCallback in src/Js.php
Retrieves the set callback.

File

src/Js.php, line 451

Class

Js
JS Callback Handler service.

Namespace

Drupal\js

Code

public function getJsParameter($name, $default = NULL, $remove = TRUE) {

  /** @var \Symfony\Component\HttpFoundation\ParameterBag $bag */
  foreach ([
    $this
      ->getRequest()->query,
    $this
      ->getRequest()->attributes,
    $this
      ->getRequest()->request,
  ] as $bag) {
    if ($value = $bag
      ->get("js_{$name}")) {
      if ($remove) {
        $bag
          ->remove("js_{$name}");
      }
      return $value;
    }
  }
  return $default;
}