Loading layout_section_classes.module +2 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ * Module file. */ use Drupal\Core\Layout\LayoutDefault; use Drupal\layout_section_classes\ClassyLayout; /** Loading @@ -13,7 +14,7 @@ use Drupal\layout_section_classes\ClassyLayout; function layout_section_classes_layout_alter(&$definitions) { /** @var \Drupal\Core\Layout\LayoutDefinition[] $definitions */ foreach ($definitions as &$definition) { if ($definition->get('classes') !== NULL) { if ($definition->get('class') === LayoutDefault::class && $definition->get('classes') !== NULL) { $definition->setClass(ClassyLayout::class); } } Loading tests/modules/layout_section_classes_test/layout_section_classes_test.layouts.yml +18 −0 Original line number Diff line number Diff line Loading @@ -28,3 +28,21 @@ test_layout: regions: content: label: Content custom_class_layout: label: Custom class category: 'LSC' template: templates/test-layout class: '\Drupal\layout_section_classes_test\NewTestClassyLayout' classes: spacing: label: 'Spacing' multiple: false required: true default: 'section--bottom-l section--top-l' options: 'section--bottom-l section--top-l': 'Standard' '': 'Tight' regions: content: label: Content tests/modules/layout_section_classes_test/src/NewTestClassyLayout.php 0 → 100644 +12 −0 Original line number Diff line number Diff line <?php namespace Drupal\layout_section_classes_test; use Drupal\layout_section_classes\ClassyLayout; /** * Test class that extends ClassyLayout. */ class NewTestClassyLayout extends ClassyLayout { } tests/src/Functional/LayoutSectionClassesTest.php +11 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace Drupal\Tests\layout_section_classes\Functional; use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage; use Drupal\layout_builder\Section; use Drupal\layout_section_classes_test\NewTestClassyLayout; use Drupal\Tests\layout_builder\Kernel\LayoutBuilderCompatibilityTestBase; use Symfony\Component\DomCrawler\Crawler; Loading Loading @@ -55,6 +56,16 @@ class LayoutSectionClassesTest extends LayoutBuilderCompatibilityTestBase { $this->assertCount(1, $crawler->filter('.background--wave-dark.background--primary-light[data-some-attribute="foo"]')); } /** * Test layouts can override the class key in layout definitions. */ public function testLayoutSectionCustomClass() { /** @var \Drupal\Core\Layout\LayoutPluginManager $plugin_manager */ $plugin_manager = \Drupal::service('plugin.manager.core.layout'); $definition = $plugin_manager->getDefinition('custom_class_layout'); $this->assertEquals(NewTestClassyLayout::class, $definition->getClass()); } /** * Render the test entity. * Loading Loading
layout_section_classes.module +2 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ * Module file. */ use Drupal\Core\Layout\LayoutDefault; use Drupal\layout_section_classes\ClassyLayout; /** Loading @@ -13,7 +14,7 @@ use Drupal\layout_section_classes\ClassyLayout; function layout_section_classes_layout_alter(&$definitions) { /** @var \Drupal\Core\Layout\LayoutDefinition[] $definitions */ foreach ($definitions as &$definition) { if ($definition->get('classes') !== NULL) { if ($definition->get('class') === LayoutDefault::class && $definition->get('classes') !== NULL) { $definition->setClass(ClassyLayout::class); } } Loading
tests/modules/layout_section_classes_test/layout_section_classes_test.layouts.yml +18 −0 Original line number Diff line number Diff line Loading @@ -28,3 +28,21 @@ test_layout: regions: content: label: Content custom_class_layout: label: Custom class category: 'LSC' template: templates/test-layout class: '\Drupal\layout_section_classes_test\NewTestClassyLayout' classes: spacing: label: 'Spacing' multiple: false required: true default: 'section--bottom-l section--top-l' options: 'section--bottom-l section--top-l': 'Standard' '': 'Tight' regions: content: label: Content
tests/modules/layout_section_classes_test/src/NewTestClassyLayout.php 0 → 100644 +12 −0 Original line number Diff line number Diff line <?php namespace Drupal\layout_section_classes_test; use Drupal\layout_section_classes\ClassyLayout; /** * Test class that extends ClassyLayout. */ class NewTestClassyLayout extends ClassyLayout { }
tests/src/Functional/LayoutSectionClassesTest.php +11 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace Drupal\Tests\layout_section_classes\Functional; use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage; use Drupal\layout_builder\Section; use Drupal\layout_section_classes_test\NewTestClassyLayout; use Drupal\Tests\layout_builder\Kernel\LayoutBuilderCompatibilityTestBase; use Symfony\Component\DomCrawler\Crawler; Loading Loading @@ -55,6 +56,16 @@ class LayoutSectionClassesTest extends LayoutBuilderCompatibilityTestBase { $this->assertCount(1, $crawler->filter('.background--wave-dark.background--primary-light[data-some-attribute="foo"]')); } /** * Test layouts can override the class key in layout definitions. */ public function testLayoutSectionCustomClass() { /** @var \Drupal\Core\Layout\LayoutPluginManager $plugin_manager */ $plugin_manager = \Drupal::service('plugin.manager.core.layout'); $definition = $plugin_manager->getDefinition('custom_class_layout'); $this->assertEquals(NewTestClassyLayout::class, $definition->getClass()); } /** * Render the test entity. * Loading