diff --git a/core/modules/block_place/block_place.routing.yml b/core/modules/block_place/block_place.routing.yml new file mode 100644 index 0000000..4d7c765 --- /dev/null +++ b/core/modules/block_place/block_place.routing.yml @@ -0,0 +1,8 @@ +block_place.admin_library: + path: 'admin/structure/block-place/library/{theme}' + defaults: + _controller: '\Drupal\block_place\Controller\PlaceBlockLibraryController::listBlocks' + _title: 'Place block' + requirements: + _access_theme: 'TRUE' + _permission: 'administer blocks' diff --git a/core/modules/block_place/src/Controller/PlaceBlockLibraryController.php b/core/modules/block_place/src/Controller/PlaceBlockLibraryController.php new file mode 100644 index 0000000..443336b --- /dev/null +++ b/core/modules/block_place/src/Controller/PlaceBlockLibraryController.php @@ -0,0 +1,36 @@ + 425, + ]); + } + } + } + return $build; + } + +} diff --git a/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php b/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php index b2d3c33..d0e5f15 100644 --- a/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php +++ b/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php @@ -6,6 +6,7 @@ use Drupal\block\Plugin\DisplayVariant\BlockPageVariant; use Drupal\Component\Serialization\Json; use Drupal\Core\Entity\EntityViewBuilderInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Routing\RedirectDestinationInterface; use Drupal\Core\Theme\ThemeManagerInterface; use Drupal\Core\Link; @@ -36,6 +37,13 @@ class PlaceBlockPageVariant extends BlockPageVariant { protected $redirectDestination; /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** * Constructs a new PlaceBlockPageVariant. * * @param array $configuration @@ -54,12 +62,15 @@ class PlaceBlockPageVariant extends BlockPageVariant { * The theme manager. * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination * The redirect destination. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The 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) { + 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) { 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; } /** @@ -74,7 +85,8 @@ public static function create(ContainerInterface $container, array $configuratio $container->get('entity_type.manager')->getViewBuilder('block'), $container->get('entity_type.manager')->getDefinition('block')->getListCacheTags(), $container->get('theme.manager'), - $container->get('redirect.destination') + $container->get('redirect.destination'), + $container->get('module_handler') ); } @@ -100,20 +112,34 @@ public function build() { $query['destination'] = $destination; } $title = $this->t('Place block in the %region region', ['%region' => $region_name]); + // @todo Remove module exists check when offcanvas library moved into + // core.services.yml. https://www.drupal.org/node/2784443 + if ($this->moduleHandler->moduleExists('outside_in')) { + $place_block_route = 'block_place.admin_library'; + $data_dialog_attributes = [ + 'data-dialog-type' => 'dialog', + 'data-dialog-renderer' => 'offcanvas', + ]; + } + else { + $place_block_route = 'block.admin_library'; + $data_dialog_attributes = [ + 'data-dialog-type' => 'modal', + 'data-dialog-options' => Json::encode([ + 'width' => 700, + ]), + ]; + } $operations['block_description'] = [ '#type' => 'inline_template', '#template' => '
{{ link }}
', '#context' => [ - 'link' => Link::createFromRoute($title, 'block.admin_library', ['theme' => $theme_name], [ + 'link' => Link::createFromRoute($title, $place_block_route, ['theme' => $theme_name], [ 'query' => $query, 'attributes' => [ 'title' => $title, 'class' => ['use-ajax', 'button', 'button--small'], - 'data-dialog-type' => 'modal', - 'data-dialog-options' => Json::encode([ - 'width' => 700, - ]), - ], + ] + $data_dialog_attributes, ]), ], ];