Commit bab4e144 authored by Ben Mullins's avatar Ben Mullins
Browse files

Issue #2253257 by Utkarsh_33, bnjmnm, hooroomoo, jhedstrom, Xano, narendraR,...

Issue #2253257 by Utkarsh_33, bnjmnm, hooroomoo, jhedstrom, Xano, narendraR, chr.fritsch, vsujeetkumar, lauriii, Manuel Garcia, borisson_, andrewmacpherson, swentel, vijaycs85, tim.plunkett, larowlan, Berdir, mgifford, bojanz, jibran, olli, runeasgar, pooja saraah, zvischutz, InternetDevels, yoroy, effulgentsia, pfrenssen, jessebeach: Use a modal for entity delete operation links
parent fa2193ff
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\Core\Entity;

use Drupal\Component\Serialization\Json;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
@@ -246,10 +247,17 @@ protected function actions(array $form, FormStateInterface $form_state) {
        '#title' => $this->t('Delete'),
        '#access' => $this->entity->access('delete'),
        '#attributes' => [
          'class' => ['button', 'button--danger'],
          'class' => ['button', 'button--danger', 'use-ajax'],
          'data-dialog-type' => 'modal',
          'data-dialog-options' => Json::encode([
            'width' => 880,
          ]),
        ],
        '#url' => $route_info,
        '#attached' => [
          'library' => 'core/drupal.dialog.ajax',
        ],
      ];
      $actions['delete']['#url'] = $route_info;
    }

    return $actions;
+12 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
use Drupal\Core\Messenger\MessengerTrait;
use Drupal\Core\Routing\RedirectDestinationTrait;
use Drupal\Core\Url;
use Drupal\Component\Serialization\Json;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\Query\QueryInterface;

@@ -151,6 +152,13 @@ protected function getDefaultOperations(EntityInterface $entity) {
      $operations['delete'] = [
        'title' => $this->t('Delete'),
        'weight' => 100,
        'attributes' => [
          'class' => ['use-ajax'],
          'data-dialog-type' => 'modal',
          'data-dialog-options' => Json::encode([
            'width' => 880,
          ]),
        ],
        'url' => $this->ensureDestination($entity->toUrl('delete-form')),
      ];
    }
@@ -202,6 +210,10 @@ public function buildOperations(EntityInterface $entity) {
    $build = [
      '#type' => 'operations',
      '#links' => $this->getOperations($entity),
      // Allow links to use modals.
      '#attached' => [
        'library' => ['core/drupal.dialog.ajax'],
      ],
    ];

    return $build;
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ public static function buildCancelLink(ConfirmFormInterface $form, Request $requ
    return [
      '#type' => 'link',
      '#title' => $form->getCancelText(),
      '#attributes' => ['class' => ['button']],
      '#attributes' => ['class' => ['button', 'dialog-cancel']],
      '#url' => $url,
      '#cache' => [
        'contexts' => [
+15 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\Tests\config\Functional;

use Drupal\Component\Serialization\Json;
use Drupal\Core\Routing\RedirectDestinationTrait;
use Drupal\config_test\Entity\ConfigTest;
use Drupal\Core\Entity\EntityStorageInterface;
@@ -71,6 +72,13 @@ public function testList() {
      'delete' => [
        'title' => 'Delete',
        'weight' => 100,
        'attributes' => [
          'class' => ['use-ajax'],
          'data-dialog-type' => 'modal',
          'data-dialog-options' => Json::encode([
            'width' => 880,
          ]),
        ],
        'url' => $entity->toUrl('delete-form')->setOption('query', $this->getRedirectDestination()->getAsArray()),
      ],
    ];
@@ -141,6 +149,13 @@ public function testList() {
      'delete' => [
        'title' => 'Delete',
        'weight' => 100,
        'attributes' => [
          'class' => ['use-ajax'],
          'data-dialog-type' => 'modal',
          'data-dialog-options' => Json::encode([
            'width' => 880,
          ]),
        ],
        'url' => $entity->toUrl('delete-form')->setOption('query', $this->getRedirectDestination()->getAsArray()),
      ],
    ];
+6 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\field_ui;

use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\Html;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityFieldManagerInterface;
@@ -194,6 +195,11 @@ public function getDefaultOperations(EntityInterface $entity) {
        'url' => $entity->toUrl("{$entity->getTargetEntityTypeId()}-field-delete-form"),
        'attributes' => [
          'title' => $this->t('Delete field.'),
          'class' => ['use-ajax'],
          'data-dialog-type' => 'modal',
          'data-dialog-options' => Json::encode([
            'width' => 880,
          ]),
        ],
      ];
    }
Loading