You are here

public function EntityDisplayFormBase::multistepAjax in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/field_ui/src/Form/EntityDisplayFormBase.php \Drupal\field_ui\Form\EntityDisplayFormBase::multistepAjax()
  2. 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 681

Class

EntityDisplayFormBase
Base class for EntityDisplay edit forms.

Namespace

Drupal\field_ui\Form

Code

public function multistepAjax($form, FormStateInterface $form_state) {
  $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">' . (isset($element['#prefix']) ? $element['#prefix'] : '');
      $element['#suffix'] = (isset($element['#suffix']) ? $element['#suffix'] : '') . '</div>';
    }
  }

  // Return the whole table.
  return $form['fields'];
}