Modal dialog popup display message when submitted

Ok so i have a custom entity and want to display a custom delete form. Have created the Route and everything works except for Drupal messenger displaying status message after submission, even after a manual refresh.

The weird thing is, if i add a ksm() output to hook_entity_delete() which is called after the entity is deleted, the status message does display.

I have added a ‘?destionation=’ parameter to the end of the link the initiates the popup, and after submit, the redirect is successful.

Here is my class, which i can get to popup in a dialog window, with the form and successful deletion and window close.

Any ideas?

class TrEntryDeleteForm extends ConfirmFormBase {

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, EntityInterface $na_entry = NULL) {

    $entry_id = $na_entry->id();

    $form['title'] = [
      '#markup' => t("<p>Title</p>"),
    ];

    $form['description'] = [
      '#markup' => t("<p class='text-center'>This action can't be undone</p>"),
    ];

    $form['entry_id'] = [
      '#type' => 'hidden',
      '#default_value' => $entry_id,
      '#required' => TRUE,
    ];

    $form['actions'] = [
      '#type' => 'actions',
    ];

    $form['actions']['cancel'] = [
      '#type' => 'submit',
      '#value' => $this->t('Cancel'),
      '#attributes' => [
        'class' => [
          'use-ajax',
          'cancel',
        ],
      ],
      '#ajax' => [
        'callback' => [$this, 'closeModalForm'],
        'event' => 'click',
      ],
    ];

    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Delete'),
    ];

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {

    $entry_entity = Drupal::entityTypeManager()->getStorage('entry')->load($entry_id);
    $entry_entity->delete();

    Drupal::messenger()->addStatus(
      t('@msg', ['@msg' => 'Entity deleted.'])
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {

  }

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    // TODO: Implement getCancelUrl() method.
  }

}


Go to Source of this post
Author Of this post: Key
Title Of post: Modal dialog popup display message when submitted
Author Link: {authorlink}