You are here

protected function WebformDialogFormTrait::buildDialogDeleteAction in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Form/WebformDialogFormTrait.php \Drupal\webform\Form\WebformDialogFormTrait::buildDialogDeleteAction()

Build webform dialog delete link.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

\Drupal\Core\Url $url: The delete URL.

3 calls to WebformDialogFormTrait::buildDialogDeleteAction()
WebformHandlerEditForm::buildForm in src/Form/WebformHandlerEditForm.php
Form constructor.
WebformUiElementEditForm::buildForm in modules/webform_ui/src/Form/WebformUiElementEditForm.php
Form constructor.
WebformVariantEditForm::buildForm in src/Form/WebformVariantEditForm.php
Form constructor.

File

src/Form/WebformDialogFormTrait.php, line 85

Class

WebformDialogFormTrait
Trait class for Webform Ajax dialog support.

Namespace

Drupal\webform\Form

Code

protected function buildDialogDeleteAction(array &$form, FormStateInterface $form_state, Url $url) {

  // WORKAROUND:
  // Create a hidden link that is clicked using jQuery.
  if ($this
    ->isDialog()) {
    $form['delete'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Delete'),
      '#url' => $url,
      '#attributes' => [
        'style' => 'display:none',
      ] + WebformDialogHelper::getModalDialogAttributes(WebformDialogHelper::DIALOG_NARROW, [
        'webform-dialog-delete-link',
      ]),
    ];
    $form['actions']['delete'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Delete'),
      '#attributes' => [
        'class' => [
          'button',
          'button--danger',
        ],
        'onclick' => "jQuery('.webform-dialog-delete-link').click(); return false;",
      ],
    ];
  }
  else {
    $form['actions']['delete'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Delete'),
      '#url' => $url,
      '#attributes' => WebformDialogHelper::getModalDialogAttributes(WebformDialogHelper::DIALOG_NARROW, [
        'button',
        'button--danger',
      ]),
    ];
  }
  WebformDialogHelper::attachLibraries($form);
}