Issue #3462896 by phenaproxima, mandclu: Allow 'region' key to be a string for placeBlockInDefaultTheme and placeBlockInAdminTheme config actions

merge-requests/9274/head^2
nod_ 2024-09-06 15:13:24 +02:00
parent d075b6c360
commit 5acde36fac
No known key found for this signature in database
GPG Key ID: 76624892606FA197
2 changed files with 20 additions and 4 deletions

View File

@ -57,13 +57,12 @@ final class PlaceBlock implements ConfigActionPluginInterface, ContainerFactoryP
$theme = $this->configFactory->get('system.theme')->get($this->whichTheme);
$value['theme'] = $theme;
if (array_key_exists('region', $value)) {
if (array_key_exists('region', $value) && is_array($value['region'])) {
// Since the recipe author might not know ahead of time what theme the
// block is in, they should supply a map whose keys are theme names and
// values are region names, so we know where to place this block. If the
// target theme is not in the map, they should supply the name of a
// fallback region. If all that fails, give up with an exception.
assert(is_array($value['region']));
$value['region'] = $value['region'][$theme] ?? $value['default_region'] ?? throw new ConfigActionException("Cannot determine which region to place this block into, because no default region was provided.");
}

View File

@ -95,7 +95,7 @@ class ConfigActionsTest extends KernelTestBase {
* @testWith ["placeBlockInDefaultTheme", "olivero", "header"]
* ["placeBlockInAdminTheme", "claro", "page_bottom"]
*/
public function testPlaceBlockInTheme(string $action, string $expected_theme, string $expected_region): void {
public function testPlaceBlockInDynamicRegion(string $action, string $expected_theme, string $expected_region): void {
$this->configActionManager->applyAction($action, 'block.block.test_block', [
'plugin' => 'system_powered_by_block',
'region' => [
@ -119,9 +119,26 @@ class ConfigActionsTest extends KernelTestBase {
]);
}
/**
* @testWith ["placeBlockInDefaultTheme", "olivero"]
* ["placeBlockInAdminTheme", "claro"]
*/
public function testPlaceBlockInStaticRegion(string $action, string $expected_theme): void {
$this->configActionManager->applyAction($action, 'block.block.test_block', [
'plugin' => 'system_powered_by_block',
'region' => 'content',
]);
$block = Block::load('test_block');
$this->assertInstanceOf(Block::class, $block);
$this->assertSame('system_powered_by_block', $block->getPluginId());
$this->assertSame($expected_theme, $block->getTheme());
$this->assertSame('content', $block->getRegion());
}
public function testPlaceBlockInDefaultRegion(): void {
$this->config('system.theme')->set('default', 'umami')->save();
$this->testPlaceBlockInTheme('placeBlockInDefaultTheme', 'umami', 'content');
$this->testPlaceBlockInDynamicRegion('placeBlockInDefaultTheme', 'umami', 'content');
}
public function testPlaceBlockAtPosition(): void {