function ConfigFormBase::doStoreConfigMap

Same name in other branches
  1. 10 core/lib/Drupal/Core/Form/ConfigFormBase.php \Drupal\Core\Form\ConfigFormBase::doStoreConfigMap()

Helper method for #after_build callback ::storeConfigKeyToFormElementMap().

Parameters

array $element: The element being processed.

\Drupal\Core\Form\FormStateInterface $form_state: The current form state.

Return value

array The processed element.

See also

\Drupal\Core\Form\ConfigFormBase::storeConfigKeyToFormElementMap()

1 call to ConfigFormBase::doStoreConfigMap()
ConfigFormBase::storeConfigKeyToFormElementMap in core/lib/Drupal/Core/Form/ConfigFormBase.php
#after_build callback which stores a map of element names to config keys.

File

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

Class

ConfigFormBase
Base class for implementing system configuration forms.

Namespace

Drupal\Core\Form

Code

protected function doStoreConfigMap(array $element, FormStateInterface $form_state) : array {
    if (array_key_exists('#config_target', $element)) {
        $map = $form_state->get(static::CONFIG_KEY_TO_FORM_ELEMENT_MAP) ?? [];
        
        /** @var \Drupal\Core\Form\ConfigTarget|string $target */
        $target = $element['#config_target'];
        if (is_string($target)) {
            $target = ConfigTarget::fromString($target);
        }
        elseif ($target->toConfig instanceof \Closure || $target->fromConfig instanceof \Closure) {
            // If the form is using closures as toConfig or fromConfig callables
            // then form cannot be cached.
            $form_state->disableCache();
        }
        foreach ($target->propertyPaths as $property_path) {
            if (isset($map[$target->configName][$property_path])) {
                throw new \LogicException(sprintf('Two #config_targets both target "%s" in the "%s" config: `%s` and `%s`.', $property_path, $target->configName, '$form[\'' . implode("']['", $map[$target->configName][$property_path]) . '\']', '$form[\'' . implode("']['", $element['#array_parents']) . '\']'));
            }
            $map[$target->configName][$property_path] = $element['#array_parents'];
        }
        $form_state->set(static::CONFIG_KEY_TO_FORM_ELEMENT_MAP, $map);
    }
    foreach (Element::children($element) as $key) {
        $element[$key] = $this->doStoreConfigMap($element[$key], $form_state);
    }
    return $element;
}

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