function ConfigTarget::getValue

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Form/ConfigTarget.php \Drupal\Core\Form\ConfigTarget::getValue()

Retrieves the mapped value from config.

Parameters

\Drupal\Core\Config\Config $config: The config object we're reading from.

Return value

mixed The mapped value, with any transformations applied.

Throws

\InvalidArgumentException Thrown if the given config object is not the one being targeted by $this->configName.

File

core/lib/Drupal/Core/Form/ConfigTarget.php, line 174

Class

ConfigTarget
Represents the mapping of a config property to a form element.

Namespace

Drupal\Core\Form

Code

public function getValue(Config $config) : mixed {
    if ($config->getName() !== $this->configName) {
        throw new \InvalidArgumentException(sprintf('Config target is associated with %s but %s given.', $this->configName, $config->getName()));
    }
    $is_multi_target = $this->isMultiTarget();
    $value = $is_multi_target ? array_map($config->get(...), $this->propertyPaths) : $config->get($this->propertyPaths[0]);
    if ($this->fromConfig) {
        $value = $is_multi_target ? ($this->fromConfig)(...$value) : ($this->fromConfig)($value);
    }
    return $value;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.