Commit 73d179af authored by catch's avatar catch

Issue #3167901 by raman.b, johnwebdev, Spokje: RemoveSectionForm assumes there is a label

parent 33c3de6f
......@@ -25,7 +25,9 @@ public function getFormId() {
*/
public function getQuestion() {
$configuration = $this->sectionStorage->getSection($this->delta)->getLayoutSettings();
if ($configuration['label']) {
// Layouts may choose to use a class that might not have a label
// configuration.
if (!empty($configuration['label'])) {
return $this->t('Are you sure you want to remove @section?', ['@section' => $configuration['label']]);
}
return $this->t('Are you sure you want to remove section @section?', ['@section' => $this->delta + 1]);
......
<?php
namespace Drupal\layout_builder_test\Plugin\Layout;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Layout\LayoutDefault;
/**
* Layout plugin without a label configuration.
*
* @Layout(
* id = "layout_without_label",
* label = @Translation("Layout Without Label"),
* regions = {
* "main" = {
* "label" = @Translation("Main Region")
* }
* },
* )
*/
class LayoutWithoutLabel extends LayoutDefault {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {}
}
......@@ -1320,6 +1320,40 @@ public function testRemovingAllSections() {
$assert_session->pageTextNotContains('The first node body');
}
/**
* Tests removing section without layout label configuration.
*/
public function testRemovingSectionWithoutLayoutLabel() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
]));
// Enable overrides.
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this->drupalGet("$field_ui_prefix/display/default");
$this->submitForm(['layout[enabled]' => TRUE], 'Save');
$this->submitForm(['layout[allow_custom]' => TRUE], 'Save');
$this->drupalGet("$field_ui_prefix/display/default/layout");
$page->clickLink('Add section');
$assert_session->linkExists('Layout Without Label');
$page->clickLink('Layout Without Label');
$page->pressButton('Add section');
$assert_session->elementsCount('css', '.layout', 2);
$assert_session->linkExists('Remove Section 1');
$this->clickLink('Remove Section 1');
$page->pressButton('Remove');
$assert_session->statusCodeEquals(200);
$assert_session->elementsCount('css', '.layout', 1);
}
/**
* Asserts that the correct layouts are available.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment