Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / layout_builder / src / Controller / LayoutBuilderController.php
index c01fea544b2bf3320b5f871d71738cdf7d541b7d..00bb40261911761f30bc0a22dcf0082578ce97e8 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Drupal\layout_builder\Controller;
 
+use Drupal\Core\Ajax\AjaxHelperTrait;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
 use Drupal\Core\Messenger\MessengerInterface;
 use Drupal\Core\Plugin\PluginFormInterface;
@@ -24,6 +25,7 @@ class LayoutBuilderController implements ContainerInjectionInterface {
 
   use LayoutBuilderContextTrait;
   use StringTranslationTrait;
+  use AjaxHelperTrait;
 
   /**
    * The layout tempstore repository.
@@ -90,6 +92,11 @@ class LayoutBuilderController implements ContainerInjectionInterface {
     $this->prepareLayout($section_storage, $is_rebuilding);
 
     $output = [];
+    if ($this->isAjax()) {
+      $output['status_messages'] = [
+        '#type' => 'status_messages',
+      ];
+    }
     $count = 0;
     for ($i = 0; $i < $section_storage->count(); $i++) {
       $output[] = $this->buildAddSectionLink($section_storage, $count);
@@ -114,6 +121,11 @@ class LayoutBuilderController implements ContainerInjectionInterface {
    *   Indicates if the layout is rebuilding.
    */
   protected function prepareLayout(SectionStorageInterface $section_storage, $is_rebuilding) {
+    // If the layout has pending changes, add a warning.
+    if ($this->layoutTempstoreRepository->has($section_storage)) {
+      $this->messenger->addWarning($this->t('You have unsaved changes.'));
+    }
+
     // Only add sections if the layout is new and empty.
     if (!$is_rebuilding && $section_storage->count() === 0) {
       $sections = [];
@@ -269,7 +281,7 @@ class LayoutBuilderController implements ContainerInjectionInterface {
       ],
       'remove' => [
         '#type' => 'link',
-        '#title' => $this->t('Remove section'),
+        '#title' => $this->t('Remove section <span class="visually-hidden">@section</span>', ['@section' => $delta + 1]),
         '#url' => Url::fromRoute('layout_builder.remove_section', [
           'section_storage_type' => $storage_type,
           'section_storage' => $storage_id,