public function VariablesController::getVariableValue in Acquia Connector 8
Same name and namespace in other branches
- 8.2 src/Controller/VariablesController.php \Drupal\acquia_connector\Controller\VariablesController::getVariableValue()
- 3.x src/Controller/VariablesController.php \Drupal\acquia_connector\Controller\VariablesController::getVariableValue()
Get a variable value by the variable name.
Parameters
string $var: Variable name.
Return value
mixed Variable value.
Throws
\UnexpectedValueException
1 call to VariablesController::getVariableValue()
- VariablesController::getVariablesData in src/
Controller/ VariablesController.php - Get all system variables.
File
- src/
Controller/ VariablesController.php, line 68
Class
- VariablesController
- Class MappingController.
Namespace
Drupal\acquia_connector\ControllerCode
public function getVariableValue($var) {
// We have no mapping for the variable.
if (empty($this->mapping[$var])) {
throw new \UnexpectedValueException($var);
}
// Variable type (for state, setting and container parameter only).
// Holds Config name for the configuration object variables.
$var_type = $this->mapping[$var][0];
// Variable machine name (for state, settings and container parameter only).
$var_name = !empty($this->mapping[$var][1]) ? $this->mapping[$var][1] : NULL;
// Variable is Drupal state.
if ($var_type == 'state') {
return \Drupal::state()
->get($var_name);
}
// Variable is Drupal setting.
if ($var_type == 'settings') {
return Settings::get($var_name);
}
// Variable is Container Parameter.
if ($var_type == 'container_parameter') {
if (\Drupal::hasContainer()) {
try {
return \Drupal::getContainer()
->getParameter($var_name);
} catch (ParameterNotFoundException $e) {
// Parameter not found.
}
}
throw new \UnexpectedValueException($var);
}
// Variable is data from Configuration object (D7 Variable).
// We can not detect this variable type so we're processing it in last turn.
$key_exists = NULL;
$config = self::getAllConfigs();
$value = NestedArray::getValue($config, $this->mapping[$var], $key_exists);
if ($key_exists) {
return $value;
}
throw new \UnexpectedValueException($var);
}