Skip to content
Snippets Groups Projects
Verified Commit 55ae0a91 authored by Gordon Heydon's avatar Gordon Heydon Committed by Lee Rowlands
Browse files

Issue #3351772 by T.Barker, gordon, amjad1233, larowlan: php warnings thrown...

Issue #3351772 by T.Barker, gordon, amjad1233, larowlan: php warnings thrown by ClassyLayout when definition_default is NULL for default_section
parent 47980c18
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@ class ClassyLayout extends LayoutDefault implements PluginFormInterface {
$build['#attributes']['class'] = $build['#attributes']['class'] ?? [];
$definitions = $this->getPluginDefinition()->get('classes');
foreach ($classes as $key => $class_set) {
$definition = $definitions[$key];
$definition = $definitions[$key] ?? NULL;
if (is_string($class_set) && $class_set) {
$build['#attributes']['class'][] = $class_set;
}
......@@ -66,7 +66,11 @@ class ClassyLayout extends LayoutDefault implements PluginFormInterface {
if (empty($class_definition['options']) || !is_array($class_definition['options'])) {
throw new \Exception('The "options" key is required for layout class definitions.');
}
$definition_default = $class_definition['default'] ?? NULL;
if ($class_definition['multiple']) {
$definition_default = $class_definition['default'] ?? [];
} else {
$definition_default = NULL;
}
$form['classes'][$key] = [
'#title' => $class_definition['label'] ?? $this->t('Classes'),
'#type' => 'select',
......
......@@ -2,6 +2,8 @@
namespace Drupal\Tests\layout_section_classes\Functional;
use Drupal\Core\Form\FormState;
use Drupal\layout_builder\LayoutEntityHelperTrait;
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
use Drupal\layout_builder\Section;
use Drupal\layout_section_classes_test\NewTestClassyLayout;
......@@ -15,6 +17,8 @@ use Symfony\Component\DomCrawler\Crawler;
*/
class LayoutSectionClassesTest extends LayoutBuilderCompatibilityTestBase {
use LayoutEntityHelperTrait;
/**
* {@inheritdoc}
*/
......@@ -54,6 +58,12 @@ class LayoutSectionClassesTest extends LayoutBuilderCompatibilityTestBase {
$this->assertCount(1, $crawler->filter('.some-region-classes.a-region-class'));
// Assert attributes work as expected.
$this->assertCount(1, $crawler->filter('.background--wave-dark.background--primary-light[data-some-attribute="foo"]'));
// Check if the default value is an array.
$plugin = \Drupal::service('plugin.manager.core.layout')->createInstance('test_layout');
$form = $plugin->buildConfigurationForm([], new FormState(), $sections->get(0));
$this->assertNotEmpty($form);
$this->assertIsArray($form['classes']['style']['#default_value']);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment