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. 11.x 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 685

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.
    switch ($op) {
        case 'edit':
            $updated_rows = [
                $trigger['#field_name'],
            ];
            $updated_columns = [
                'plugin',
            ];
            break;
        case 'update':
        case 'cancel':
            $updated_rows = [
                $trigger['#field_name'],
            ];
            $updated_columns = [
                'plugin',
                'settings_summary',
                'settings_edit',
            ];
            break;
        case 'refresh_table':
            $updated_rows = array_values(explode(' ', $form_state->getValue('refresh_rows')));
            $updated_columns = [
                'settings_summary',
                'settings_edit',
            ];
            break;
    }
    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.