function TempstoreConverter::convertVariable

Same name in other branches
  1. 4.0.x src/ParamConverter/TempstoreConverter.php \Drupal\ctools\ParamConverter\TempstoreConverter::convertVariable()

A helper function for converting string variable names from the defaults.

Parameters

mixed $name: If name is a string in the format of {var} it will parse the defaults for a 'var' default. If $name isn't a string or isn't a slug, it will return the raw $name value. If no default is found, it will return NULL.

array $defaults: The route defaults array.

Return value

mixed The value of a variable in defaults.

1 call to TempstoreConverter::convertVariable()
TempstoreConverter::convert in src/ParamConverter/TempstoreConverter.php
Converts path variables to their corresponding objects.

File

src/ParamConverter/TempstoreConverter.php, line 147

Class

TempstoreConverter
Parameter converter for pulling entities out of the tempstore.

Namespace

Drupal\ctools\ParamConverter

Code

protected function convertVariable($name, array $defaults) {
    if (is_string($name) && strpos($name, '{') === 0) {
        $length = strlen($name);
        $name = substr($name, 1, $length - 2);
        return $defaults[$name] ?? NULL;
    }
    return $name;
}