Skip to content
Snippets Groups Projects
Verified Commit 73c60599 authored by Dave Long's avatar Dave Long
Browse files

Issue #3488664 by phenaproxima: The PlaceBlock config action breaks when...

Issue #3488664 by phenaproxima: The PlaceBlock config action breaks when placing a block in an empty region

(cherry picked from commit 43717fbb)
parent 55d2288b
No related branches found
No related tags found
3 merge requests!11958Issue #3490507 by alexpott, smustgrave: Fix bogus mocking in...,!11769Issue #3517987: Add option to contextual filters to encode slashes in query parameter.,!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4
Pipeline #348252 passed with warnings
Pipeline: drupal

#348296

    Pipeline: drupal

    #348294

      Pipeline: drupal

      #348288

        +7
        ...@@ -74,15 +74,17 @@ public function apply(string $configName, mixed $value): void { ...@@ -74,15 +74,17 @@ public function apply(string $configName, mixed $value): void {
        'theme' => $theme, 'theme' => $theme,
        'region' => $value['region'], 'region' => $value['region'],
        ]); ]);
        // Sort the blocks by weight. Don't use \Drupal\block\Entity\Block::sort() if ($blocks) {
        // here because it seems to be intended to sort blocks in the UI, where // Sort the blocks by weight. Don't use \Drupal\block\Entity\Block::sort()
        // we really just want to get the weights right in this situation. // here because it seems to be intended to sort blocks in the UI, where
        uasort($blocks, fn (BlockInterface $a, BlockInterface $b) => $a->getWeight() <=> $b->getWeight()); // we really just want to get the weights right in this situation.
        uasort($blocks, fn (BlockInterface $a, BlockInterface $b) => $a->getWeight() <=> $b->getWeight());
        $value['weight'] = match ($value['position']) { $value['weight'] = match ($value['position']) {
        'first' => reset($blocks)->getWeight() - 1, 'first' => reset($blocks)->getWeight() - 1,
        'last' => end($blocks)->getWeight() + 1, 'last' => end($blocks)->getWeight() + 1,
        }; };
        }
        } }
        // Remove values that are not valid properties of block entities. // Remove values that are not valid properties of block entities.
        unset($value['position'], $value['default_region']); unset($value['position'], $value['default_region']);
        ......
        ...@@ -163,4 +163,28 @@ public function testPlaceBlockAtPosition(): void { ...@@ -163,4 +163,28 @@ public function testPlaceBlockAtPosition(): void {
        $this->assertSame('last', end($blocks)); $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());
        }
        } }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment