function ConfigTarget::fromForm

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

Gets the config target object for an element from a form array.

Parameters

array $array_parents: The array to locate the element in the form.

array $form: The form array.

Return value

self A ConfigTarget instance.

5 calls to ConfigTarget::fromForm()
ConfigFormBase::copyFormValuesToConfig in core/lib/Drupal/Core/Form/ConfigFormBase.php
Copies form values to Config keys.
ConfigFormBase::validateForm in core/lib/Drupal/Core/Form/ConfigFormBase.php
Form validation handler.
ConfigTargetTest::testFromFormConfigTarget in core/tests/Drupal/Tests/Core/Form/ConfigTargetTest.php
@covers ::fromForm
ConfigTargetTest::testFromFormException in core/tests/Drupal/Tests/Core/Form/ConfigTargetTest.php
@covers ::fromForm @dataProvider providerTestFromFormException
ConfigTargetTest::testFromFormString in core/tests/Drupal/Tests/Core/Form/ConfigTargetTest.php
@covers ::fromForm @covers ::fromString

File

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

Class

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

Namespace

Drupal\Core\Form

Code

public static function fromForm(array $array_parents, array $form) : self {
    $element = NestedArray::getValue($form, $array_parents);
    if (!isset($element['#config_target'])) {
        throw new \LogicException('The form element [' . implode('][', $array_parents) . '] does not have the #config_target property set');
    }
    $target = $element['#config_target'];
    if (is_string($target)) {
        $target = ConfigTarget::fromString($target);
    }
    if (!$target instanceof ConfigTarget) {
        throw new \LogicException('The form element [' . implode('][', $array_parents) . '] #config_target property is not a string or a ConfigTarget object');
    }
    // Add the element information to the config target object.
    $target->elementParents = $element['#parents'];
    return $target;
}

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