Pull merge.
[yaffs-website] / web / core / modules / layout_builder / src / Controller / LayoutBuilderController.php
index 8f7666f579a570920a045d9bc610523688afe262..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 = [];
@@ -161,7 +173,7 @@ class LayoutBuilderController implements ContainerInjectionInterface {
           ],
           [
             'attributes' => [
-              'class' => ['use-ajax'],
+              'class' => ['use-ajax', 'new-section__link'],
               'data-dialog-type' => 'dialog',
               'data-dialog-renderer' => 'off_canvas',
             ],
@@ -170,7 +182,7 @@ class LayoutBuilderController implements ContainerInjectionInterface {
       ],
       '#type' => 'container',
       '#attributes' => [
-        'class' => ['add-section'],
+        'class' => ['new-section'],
       ],
     ];
   }
@@ -226,7 +238,7 @@ class LayoutBuilderController implements ContainerInjectionInterface {
           ],
           [
             'attributes' => [
-              'class' => ['use-ajax'],
+              'class' => ['use-ajax', 'new-block__link'],
               'data-dialog-type' => 'dialog',
               'data-dialog-renderer' => 'off_canvas',
             ],
@@ -234,7 +246,7 @@ class LayoutBuilderController implements ContainerInjectionInterface {
         ),
       ];
       $build[$region]['layout_builder_add_block']['#type'] = 'container';
-      $build[$region]['layout_builder_add_block']['#attributes'] = ['class' => ['add-block']];
+      $build[$region]['layout_builder_add_block']['#attributes'] = ['class' => ['new-block']];
       $build[$region]['layout_builder_add_block']['#weight'] = 1000;
       $build[$region]['#attributes']['data-region'] = $region;
       $build[$region]['#attributes']['class'][] = 'layout-builder--layout__region';
@@ -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,