function AjaxFormBlock::updateOptions

Same name in other branches
  1. 8.9.x core/modules/system/tests/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php \Drupal\ajax_forms_test\Plugin\Block\AjaxFormBlock::updateOptions()
  2. 10 core/modules/system/tests/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php \Drupal\ajax_forms_test\Plugin\Block\AjaxFormBlock::updateOptions()
  3. 11.x core/modules/system/tests/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php \Drupal\ajax_forms_test\Plugin\Block\AjaxFormBlock::updateOptions()

Updates the options of a select list.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The updated form element.

File

core/modules/system/tests/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php, line 125

Class

AjaxFormBlock
Provides an AJAX form block.

Namespace

Drupal\ajax_forms_test\Plugin\Block

Code

public function updateOptions(array $form, FormStateInterface $form_state) {
    $form['test1']['#options']['option1'] = $this->t('Option 1!!!');
    $form['test1']['#options'] += [
        'option3' => $this->t('Option 3'),
        'option4' => $this->t('Option 4'),
    ];
    return $form['test1'];
}

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