You are here

function entity_reference_actions_form_alter in Entity reference actions 1.x

Implements hook_form_alter().

File

./entity_reference_actions.module, line 66
Entity reference actions module hooks.

Code

function entity_reference_actions_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $is_ajax = FALSE;
  foreach ([
    'drupal_ajax',
    'drupal_modal',
    'drupal_dialog',
  ] as $wrapper) {
    if (strpos(\Drupal::request()
      ->get(MainContentViewSubscriber::WRAPPER_FORMAT), $wrapper) !== FALSE) {
      $is_ajax = TRUE;
    }
  }
  if (!$is_ajax || !$form_state
    ->getFormObject() instanceof ConfirmFormBase) {
    return;
  }
  $form['actions']['submit']['#ajax']['callback'] = [
    EntityReferenceActionsHandler::class,
    'dialogAjaxSubmit',
  ];
  $form['actions']['cancel']['#attributes']['class'][] = 'dialog-cancel';
}