Skip to content
Snippets Groups Projects
Verified Commit 1f94e17f authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2833116 by smustgrave, mohit_aghera, Ratan Priya, _pratik_, _shY,...

Issue #2833116 by smustgrave, mohit_aghera, Ratan Priya, _pratik_, _shY, alexpott, nitin_lama, acbramley, quietone, larowlan, Peter van den Heuvel, ameymudras, alexpott: When Placing a Block on 'Configure Block' page the originally selected region is lost
parent 23bb407d
No related branches found
No related tags found
Loading
Pipeline #121172 canceled
......@@ -115,6 +115,7 @@ public function save(array $form, FormStateInterface $form_state) {
[
'plugin_id' => 'block_content:' . $block->uuid(),
'theme' => $theme,
'region' => $this->getRequest()->query->getString('region'),
]
);
}
......
......@@ -4,13 +4,42 @@
use Drupal\Core\Menu\LocalActionDefault;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Modifies the 'Add content block' local action.
*/
class BlockContentAddLocalAction extends LocalActionDefault {
/**
* Constructs a BlockContentAddLocalAction object.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
RouteProviderInterface $routeProvider,
protected RequestStack $requestStack,
) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $routeProvider);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('router.route_provider'),
$container->get('request_stack'),
);
}
/**
* {@inheritdoc}
*/
......@@ -20,6 +49,12 @@ public function getOptions(RouteMatchInterface $route_match) {
if ($theme = $route_match->getParameter('theme')) {
$options['query']['theme'] = $theme;
}
// If the current request has a region, append it to the query string.
if ($region = $this->requestStack->getCurrentRequest()->query->getString('region')) {
$options['query']['region'] = $region;
}
// Adds a destination on content block listing.
if ($route_match->getRouteName() == 'entity.block_content.collection') {
$options['query']['destination'] = Url::fromRoute('<current>')->toString();
......
......@@ -71,6 +71,22 @@ protected function setUp(): void {
]);
}
/**
* Tests the region value when a new block is saved.
*/
public function testBlockRegionPlacement(): void {
$this->drupalLogin($this->drupalCreateUser($this->permissions));
$this->drupalGet("admin/structure/block/library/stark", ['query' => ['region' => 'content']]);
$this->clickLink('Add content block');
$this->assertSession()->statusCodeEquals(200);
$edit = [
'info[0][value]' => 'foo',
];
$this->submitForm($edit, 'Save');
$this->assertSession()->fieldValueEquals('region', 'content');
}
/**
* Tests the content block listing page with different permissions.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment