Commit 5a573959 authored by Eric Goodwin's avatar Eric Goodwin Committed by Lee Rowlands
Browse files

Issue #3272623 by Eric115: Only set the layout class for definitions using LayoutDefault

parent a9262c1b
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
 * Module file.
 */

use Drupal\Core\Layout\LayoutDefault;
use Drupal\layout_section_classes\ClassyLayout;

/**
@@ -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);
    }
  }
+18 −0
Original line number Diff line number Diff line
@@ -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
+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 {

}
+11 −0
Original line number Diff line number Diff line
@@ -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;

@@ -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.
   *