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;
use LayoutBuilderContextTrait;
use StringTranslationTrait;
+ use AjaxHelperTrait;
/**
* The layout tempstore repository.
$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);
* 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 = [];
],
'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,