diff --git a/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php b/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php index 74fe544310..709c4e6236 100644 --- a/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php +++ b/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php @@ -5,6 +5,7 @@ use Drupal\block\BlockRepositoryInterface; use Drupal\block\Plugin\DisplayVariant\BlockPageVariant; use Drupal\Component\Serialization\Json; +use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityViewBuilderInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Link; @@ -44,6 +45,13 @@ class PlaceBlockPageVariant extends BlockPageVariant { protected $moduleHandler; /** + * The block storage handler. + * + * @var \Drupal\Core\Entity\EntityStorageInterface + */ + protected $blockStorage; + + /** * Constructs a new PlaceBlockPageVariant. * * @param array $configuration @@ -64,13 +72,16 @@ class PlaceBlockPageVariant extends BlockPageVariant { * The redirect destination. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. + * @param \Drupal\Core\Entity\EntityStorageInterface $block_storage + * The block storage handler. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, BlockRepositoryInterface $block_repository, EntityViewBuilderInterface $block_view_builder, array $block_list_cache_tags, ThemeManagerInterface $theme_manager, RedirectDestinationInterface $redirect_destination, ModuleHandlerInterface $module_handler) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, BlockRepositoryInterface $block_repository, EntityViewBuilderInterface $block_view_builder, array $block_list_cache_tags, ThemeManagerInterface $theme_manager, RedirectDestinationInterface $redirect_destination, ModuleHandlerInterface $module_handler, EntityStorageInterface $block_storage) { parent::__construct($configuration, $plugin_id, $plugin_definition, $block_repository, $block_view_builder, $block_list_cache_tags); $this->themeManager = $theme_manager; $this->redirectDestination = $redirect_destination; $this->moduleHandler = $module_handler; + $this->blockStorage = $block_storage; } /** @@ -86,7 +97,8 @@ public static function create(ContainerInterface $container, array $configuratio $container->get('entity_type.manager')->getDefinition('block')->getListCacheTags(), $container->get('theme.manager'), $container->get('redirect.destination'), - $container->get('module_handler') + $container->get('module_handler'), + $container->get('entity_type.manager')->getStorage('block') ); } @@ -108,8 +120,14 @@ public function build() { $query = [ 'region' => $region, ]; + + if ($destination) { - $query['destination'] = $destination . "?region_sort=$region"; + $query['destination'] = $destination; + if ($this->blockStorage->loadByProperties(['theme' => $theme_name, 'region' => $region])) { + $query['destination'] .= "?region_sort=$region"; + } + } $title = $this->t('Place block in the %region region', ['%region' => $region_name]); // @todo Remove module exists check when off_canvas library moved into