Pull merge.
[yaffs-website] / web / core / modules / block / src / BlockListBuilder.php
index 37b2e8bfc346ea5f1cfe23cbeff552f9c224c2fe..d2286fcdd3644cd9b90a490a45e0a3cb399e31b7 100644 (file)
@@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Form\FormBuilderInterface;
 use Drupal\Core\Form\FormInterface;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Messenger\MessengerInterface;
 use Drupal\Core\Theme\ThemeManagerInterface;
 use Drupal\Core\Url;
 use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -56,6 +57,13 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
    */
   protected $limit = FALSE;
 
+  /**
+   * The messenger.
+   *
+   * @var \Drupal\Core\Messenger\MessengerInterface
+   */
+  protected $messenger;
+
   /**
    * Constructs a new BlockListBuilder object.
    *
@@ -68,11 +76,12 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
    * @param \Drupal\Core\Form\FormBuilderInterface $form_builder
    *   The form builder.
    */
-  public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ThemeManagerInterface $theme_manager, FormBuilderInterface $form_builder) {
+  public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ThemeManagerInterface $theme_manager, FormBuilderInterface $form_builder, MessengerInterface $messenger) {
     parent::__construct($entity_type, $storage);
 
     $this->themeManager = $theme_manager;
     $this->formBuilder = $form_builder;
+    $this->messenger = $messenger;
   }
 
   /**
@@ -83,7 +92,8 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
       $entity_type,
       $container->get('entity.manager')->getStorage($entity_type->id()),
       $container->get('theme.manager'),
-      $container->get('form_builder')
+      $container->get('form_builder'),
+      $container->get('messenger')
     );
   }
 
@@ -212,7 +222,7 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
         '#theme_wrappers' => [
           'container' => [
             '#attributes' => ['class' => 'region-title__action'],
-          ]
+          ],
         ],
         '#prefix' => $title,
         '#type' => 'link',
@@ -344,6 +354,23 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
 
     if (isset($operations['delete'])) {
       $operations['delete']['title'] = $this->t('Remove');
+      // Block operation links should have the `block-placement` query string
+      // parameter removed to ensure that JavaScript does not receive a block
+      // name that has been recently removed.
+      foreach ($operations as $operation) {
+        /** @var \Drupal\Core\Url $url */
+        $url = $operation['url'];
+        $query = $url->getOption('query');
+        $destination = $query['destination'];
+
+        $destinationUrl = Url::fromUserInput($destination);
+        $destinationQuery = $destinationUrl->getOption('query');
+        unset($destinationQuery['block-placement']);
+
+        $destinationUrl->setOption('query', $destinationQuery);
+        $query['destination'] = $destinationUrl->toString();
+        $url->setOption('query', $query);
+      }
     }
     return $operations;
   }
@@ -367,7 +394,7 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
       $entity->setRegion($entity_values['region']);
       $entity->save();
     }
-    drupal_set_message(t('The block settings have been updated.'));
+    $this->messenger->addStatus($this->t('The block settings have been updated.'));
 
     // Remove any previously set block placement.
     $this->request->query->remove('block-placement');