Loading core/modules/block/src/Plugin/ConfigAction/PlaceBlock.php +10 −8 Original line number Diff line number Diff line Loading @@ -74,6 +74,7 @@ public function apply(string $configName, mixed $value): void { 'theme' => $theme, 'region' => $value['region'], ]); if ($blocks) { // Sort the blocks by weight. Don't use \Drupal\block\Entity\Block::sort() // here because it seems to be intended to sort blocks in the UI, where // we really just want to get the weights right in this situation. Loading @@ -84,6 +85,7 @@ public function apply(string $configName, mixed $value): void { 'last' => end($blocks)->getWeight() + 1, }; } } // Remove values that are not valid properties of block entities. unset($value['position'], $value['default_region']); // Ensure a weight is set by default. Loading core/modules/block/tests/src/Kernel/ConfigActionsTest.php +24 −0 Original line number Diff line number Diff line Loading @@ -163,4 +163,28 @@ public function testPlaceBlockAtPosition(): void { $this->assertSame('last', end($blocks)); } /** * Tests using the PlaceBlock action in an empty region. */ public function testPlaceBlockInEmptyRegion(): void { /** @var \Drupal\Core\Entity\Query\QueryInterface $query */ $query = $this->container->get(EntityTypeManagerInterface::class) ->getStorage('block') ->getQuery() ->count() ->condition('theme', 'olivero') ->condition('region', 'footer_top'); $this->assertSame(0, $query->execute()); // Place a block in that region. $this->configActionManager->applyAction('placeBlockInDefaultTheme', 'block.block.test', [ 'plugin' => 'system_powered_by_block', 'region' => [ 'olivero' => 'footer_top', ], 'position' => 'first', ]); $this->assertSame(1, $query->execute()); } } Loading
core/modules/block/src/Plugin/ConfigAction/PlaceBlock.php +10 −8 Original line number Diff line number Diff line Loading @@ -74,6 +74,7 @@ public function apply(string $configName, mixed $value): void { 'theme' => $theme, 'region' => $value['region'], ]); if ($blocks) { // Sort the blocks by weight. Don't use \Drupal\block\Entity\Block::sort() // here because it seems to be intended to sort blocks in the UI, where // we really just want to get the weights right in this situation. Loading @@ -84,6 +85,7 @@ public function apply(string $configName, mixed $value): void { 'last' => end($blocks)->getWeight() + 1, }; } } // Remove values that are not valid properties of block entities. unset($value['position'], $value['default_region']); // Ensure a weight is set by default. Loading
core/modules/block/tests/src/Kernel/ConfigActionsTest.php +24 −0 Original line number Diff line number Diff line Loading @@ -163,4 +163,28 @@ public function testPlaceBlockAtPosition(): void { $this->assertSame('last', end($blocks)); } /** * Tests using the PlaceBlock action in an empty region. */ public function testPlaceBlockInEmptyRegion(): void { /** @var \Drupal\Core\Entity\Query\QueryInterface $query */ $query = $this->container->get(EntityTypeManagerInterface::class) ->getStorage('block') ->getQuery() ->count() ->condition('theme', 'olivero') ->condition('region', 'footer_top'); $this->assertSame(0, $query->execute()); // Place a block in that region. $this->configActionManager->applyAction('placeBlockInDefaultTheme', 'block.block.test', [ 'plugin' => 'system_powered_by_block', 'region' => [ 'olivero' => 'footer_top', ], 'position' => 'first', ]); $this->assertSame(1, $query->execute()); } }