function EntityDisplayFormBase::multistepAjax

Same name and namespace in other branches
  1. 9 core/modules/field_ui/src/Form/EntityDisplayFormBase.php \Drupal\field_ui\Form\EntityDisplayFormBase::multistepAjax()
  2. 8.9.x core/modules/field_ui/src/Form/EntityDisplayFormBase.php \Drupal\field_ui\Form\EntityDisplayFormBase::multistepAjax()
  3. 10 core/modules/field_ui/src/Form/EntityDisplayFormBase.php \Drupal\field_ui\Form\EntityDisplayFormBase::multistepAjax()

Ajax handler for multistep buttons.

File

core/modules/field_ui/src/Form/EntityDisplayFormBase.php, line 698

Class

EntityDisplayFormBase
Base class for EntityDisplay edit forms.

Namespace

Drupal\field_ui\Form

Code

public function multistepAjax($form, FormStateInterface $form_state) {
    $response = new AjaxResponse();
    $trigger = $form_state->getTriggeringElement();
    $op = $trigger['#op'];
    // Pick the elements that need to receive the ajax-new-content effect.
    $updated_rows = match ($op) {    'edit' => [
            $trigger['#field_name'],
        ],
        'update', 'cancel' => [
            $trigger['#field_name'],
        ],
        'refresh_table' => array_values(explode(' ', $form_state->getValue('refresh_rows'))),
    
    };
    $updated_columns = match ($op) {    'edit' => [
            'plugin',
        ],
        'update', 'cancel' => [
            'plugin',
            'settings_summary',
            'settings_edit',
        ],
        'refresh_table' => [
            'settings_summary',
            'settings_edit',
        ],
    
    };
    foreach ($updated_rows as $name) {
        foreach ($updated_columns as $key) {
            $element =& $form['fields'][$name][$key];
            $element['#prefix'] = '<div class="ajax-new-content">' . ($element['#prefix'] ?? '');
            $element['#suffix'] = ($element['#suffix'] ?? '') . '</div>';
        }
    }
    // Replace the whole table.
    $response->addCommand(new ReplaceCommand('#field-display-overview-wrapper', $form['fields']));
    // Add "row updated" warning after the table has been replaced.
    if (!in_array($op, [
        'cancel',
        'edit',
    ])) {
        foreach ($updated_rows as $name) {
            // The ID of the rendered table row is `$name` processed by getClass().
            // @see \Drupal\field_ui\Element\FieldUiTable::tablePreRender
            $response->addCommand(new TabledragWarningCommand(Html::getClass($name), 'field-display-overview'));
        }
    }
    return $response;
}

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