You are here

function private_message_form_alter in Private Message 8

Same name and namespace in other branches
  1. 8.2 private_message.module \private_message_form_alter()

Implements hook_form_alter().

File

./private_message.module, line 315
Contains hooks for the private message module.

Code

function private_message_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // Act on any implementation of the private message entity form. This form
  // can potentially exist multiple times on a page, so the form ID will be
  // dynamic in such a case.
  if (preg_match('/^private_message_add_form/', $form_id)) {

    // The form is only ajaxified if/when thread_members has been set.
    if ($form_state
      ->get('thread_members')) {

      // Add a unique wrapper around the entire form. The build ID will always
      // be unique.
      $form['#prefix'] = '<div id="' . $form['#build_id'] . '">';
      $form['#suffix'] = '</div>';

      // Set the wrapper to the #ajax on the form button.
      $form['actions']['submit']['#ajax']['wrapper'] = $form['#build_id'];

      // Ensure ajax loaded buttons have a unique ID on every ajax load.
      $form['actions']['submit-' . \Drupal::time()
        ->getRequestTime()] = $form['actions']['submit'];
      $form['actions']['submit']['#access'] = FALSE;
    }
  }
}