diff -u b/core/modules/layout_builder/src/Annotation/SectionStorage.php b/core/modules/layout_builder/src/Annotation/SectionStorage.php --- b/core/modules/layout_builder/src/Annotation/SectionStorage.php +++ b/core/modules/layout_builder/src/Annotation/SectionStorage.php @@ -23,6 +23,13 @@ public $id; /** + * The plugin weight. + * + * @var int + */ + public $weight = 0; + + /** * Any required context definitions. * * @var array diff -u b/core/modules/layout_builder/src/SectionStorage/SectionStorageManager.php b/core/modules/layout_builder/src/SectionStorage/SectionStorageManager.php --- b/core/modules/layout_builder/src/SectionStorage/SectionStorageManager.php +++ b/core/modules/layout_builder/src/SectionStorage/SectionStorageManager.php @@ -2,6 +2,7 @@ namespace Drupal\layout_builder\SectionStorage; +use Drupal\Component\Utility\SortArray; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\Context\ContextAwarePluginManagerTrait; @@ -44,0 +46,18 @@ + protected function findDefinitions() { + $definitions = parent::findDefinitions(); + + uasort($definitions, function (SectionStorageDefinition $a, SectionStorageDefinition $b) { + $a = [ + 'weight' => $a->get('weight'), + ]; + $b = [ + 'weight' => $b->get('weight'), + ]; + return SortArray::sortByWeightElement($a, $b); + }); + return $definitions; + } + + /** + * {@inheritdoc} + */ diff -u b/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module b/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module --- b/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module +++ b/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module @@ -68,2 +68,3 @@ $storages['overrides']->setClass(OverridesSectionStorage::class); + $storages['overrides']->set('weight', -10); } diff -u b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php --- b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php @@ -546,6 +546,16 @@ $this->getSession()->reload(); $state->resetCache(); $this->assertTrue($state->get($state_key)); + + // Test that plugin weights are respected. + /** @var \Drupal\layout_builder\SectionStorage\SectionStorageDefinition[] $definitions */ + $definitions = $this->container + ->get('plugin.manager.layout_builder.section_storage') + ->getDefinitions(); + + $this->assertSame('overrides', key($definitions)); + $this->assertSame(-10, $definitions['overrides']->get('weight')); + $this->assertSame(0, $definitions['defaults']->get('weight')); } }