You are here

function entity_browser_form_alter in Entity Browser 8.2

Same name and namespace in other branches
  1. 8 entity_browser.module \entity_browser_form_alter()

Implements hook_form_alter().

File

./entity_browser.module, line 71
Allows to flexibly create, browse and select entities.

Code

function entity_browser_form_alter(&$form, FormStateInterface &$form_state) {
  $entity_browser_dialog_edit = \Drupal::service('request_stack')
    ->getCurrentRequest()
    ->get('_route');
  if ($entity_browser_dialog_edit == 'entity_browser.edit_form') {

    // Let's allow the save button only.
    foreach (Element::children($form['actions']) as $key) {
      $form['actions'][$key]['#access'] = $key == 'submit';
    }

    // Use Ajax.
    $form['actions']['submit']['#ajax'] = [
      'url' => Url::fromRoute('entity_browser.edit_form', [
        'entity_type' => $form_state
          ->getFormObject()
          ->getEntity()
          ->getEntityTypeId(),
        'entity' => $form_state
          ->getFormObject()
          ->getEntity()
          ->id(),
      ]),
      'options' => [
        'query' => [
          'details_id' => \Drupal::request()->query
            ->get('details_id'),
        ],
      ],
      'disable-refocus' => TRUE,
    ];
  }
}