function ConfigFormBase::loadDefaultValuesFromConfig

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Form/ConfigFormBase.php \Drupal\Core\Form\ConfigFormBase::loadDefaultValuesFromConfig()

Process callback to recursively load default values from #config_target.

Parameters

array $element: The form element.

Return value

array The form element, with its default value populated.

File

core/lib/Drupal/Core/Form/ConfigFormBase.php, line 107

Class

ConfigFormBase
Base class for implementing system configuration forms.

Namespace

Drupal\Core\Form

Code

public function loadDefaultValuesFromConfig(array $element) : array {
    if (array_key_exists('#config_target', $element) && !array_key_exists('#default_value', $element)) {
        $target = $element['#config_target'];
        if (is_string($target)) {
            $target = ConfigTarget::fromString($target);
        }
        $config = $this->configFactory()
            ->getEditable($target->configName);
        $element['#default_value'] = $target->getValue($config);
    }
    foreach (Element::children($element) as $key) {
        $element[$key] = $this->loadDefaultValuesFromConfig($element[$key]);
    }
    return $element;
}

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