EntityDisplayFormBase::multistepAjax

public EntityDisplayFormBase::multistepAjax($form, FormStateInterface $form_state)

Ajax handler for multistep buttons.

File

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

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 = array($trigger['#field_name']);
      $updated_columns = array('plugin');
      break;

    case 'update':
    case 'cancel':
      $updated_rows = array($trigger['#field_name']);
      $updated_columns = array('plugin', 'settings_summary', 'settings_edit');
      break;

    case 'refresh_table':
      $updated_rows = array_values(explode(' ', $form_state->getValue('refresh_rows')));
      $updated_columns = array('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'];
}
doc_Drupal
2016-10-29 09:05:25
Comments
Leave a Comment

Please login to continue.