Verified Commit 642dbc74 authored by godotislate's avatar godotislate
Browse files

task: #3613243 Convert block.module routes to attributes

By: longwave
(cherry picked from commit 8d4627ea)
parent d5bb973e
Loading
Loading
Loading
Loading
Loading
+0 −71
Original line number Diff line number Diff line
block.admin_demo:
  path: '/admin/structure/block/demo/{theme}'
  defaults:
    _controller: '\Drupal\block\Controller\BlockController::demo'
    _title_callback: 'theme_handler:getName'
  requirements:
    _access_theme: 'TRUE'
    _permission: 'administer blocks'
  options:
    _admin_route: FALSE

entity.block.delete_form:
  path: '/admin/structure/block/manage/{block}/delete'
  defaults:
@@ -24,63 +13,3 @@ entity.block.edit_form:
    _title: 'Configure block'
  requirements:
    _entity_access: 'block.update'

entity.block.enable:
  path: '/admin/structure/block/manage/{block}/enable'
  defaults:
    _controller: '\Drupal\block\Controller\BlockController::performOperation'
    op: enable
  requirements:
    _entity_access: 'block.enable'
    _csrf_token: 'TRUE'

entity.block.disable:
  path: '/admin/structure/block/manage/{block}/disable'
  defaults:
    _controller: '\Drupal\block\Controller\BlockController::performOperation'
    op: disable
  requirements:
    _entity_access: 'block.disable'
    _csrf_token: 'TRUE'

block.admin_display:
  path: '/admin/structure/block'
  defaults:
    _controller: '\Drupal\block\Controller\BlockListController::listing'
    _title: 'Block layout'
  requirements:
    _permission: 'administer blocks'

block.admin_display_theme:
  path: '/admin/structure/block/list/{theme}'
  defaults:
    _controller: '\Drupal\block\Controller\BlockListController::listing'
    _title: 'Block layout'
  requirements:
    _access_theme: 'TRUE'
    _permission: 'administer blocks'

block.admin_library:
  path: '/admin/structure/block/library/{theme}'
  defaults:
    _controller: '\Drupal\block\Controller\BlockLibraryController::listBlocks'
    _title: 'Place block'
  requirements:
    _access_theme: 'TRUE'
    _permission: 'administer blocks'

block.admin_add:
  path: '/admin/structure/block/add/{plugin_id}/{theme}'
  defaults:
    _controller: '\Drupal\block\Controller\BlockAddController::blockAddConfigureForm'
    theme: null
    _title: 'Configure block'
  requirements:
    _permission: 'administer blocks'

block.category_autocomplete:
  path: '/block-category/autocomplete'
  defaults:
    _controller: '\Drupal\block\Controller\CategoryAutocompleteController::autocomplete'
  requirements:
    _permission: 'administer blocks'
+11 −0
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
namespace Drupal\block\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Symfony\Component\Routing\Attribute\Route;

/**
 * Controller for building the block instance add form.
@@ -20,6 +22,15 @@ class BlockAddController extends ControllerBase {
   * @return array
   *   The block instance edit form.
   */
  #[Route(
    path: '/admin/structure/block/add/{plugin_id}/{theme}',
    name: 'block.admin_add',
    requirements: ['_permission' => 'administer blocks'],
    defaults: [
      'theme' => NULL,
      '_title' => new TranslatableMarkup('Configure block'),
    ],
  )]
  public function blockAddConfigureForm($plugin_id, $theme) {
    // Create a block entity.
    $entity = $this->entityTypeManager()->getStorage('block')->create(['plugin' => $plugin_id, 'theme' => $theme]);
+29 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
use Drupal\Core\Theme\ThemeManagerInterface;
use Drupal\Core\Url;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Attribute\Route;

/**
 * Controller routines for admin block routes.
@@ -32,6 +33,24 @@ public function __construct(
   * @return \Symfony\Component\HttpFoundation\RedirectResponse
   *   A redirect back to the listing page.
   */
  #[Route(
    path: '/admin/structure/block/manage/{block}/enable',
    name: 'entity.block.enable',
    requirements: [
      '_entity_access' => 'block.enable',
      '_csrf_token' => 'TRUE',
    ],
    defaults: ['op' => 'enable'],
  )]
  #[Route(
    path: '/admin/structure/block/manage/{block}/disable',
    name: 'entity.block.disable',
    requirements: [
      '_entity_access' => 'block.disable',
      '_csrf_token' => 'TRUE',
    ],
    defaults: ['op' => 'disable'],
  )]
  public function performOperation(BlockInterface $block, $op) {
    $block->$op()->save();
    $this->messenger()->addStatus($this->t('The block settings have been updated.'));
@@ -47,6 +66,16 @@ public function performOperation(BlockInterface $block, $op) {
   * @return array
   *   A #type 'page' render array containing the block region demo.
   */
  #[Route(
    path: '/admin/structure/block/demo/{theme}',
    name: 'block.admin_demo',
    requirements: [
      '_access_theme' => 'TRUE',
      '_permission' => 'administer blocks',
    ],
    options: ['_admin_route' => FALSE],
    defaults: ['_title_callback' => 'theme_handler:getName'],
  )]
  public function demo($theme) {
    if (!$this->themeHandler->hasUi($theme)) {
      throw new NotFoundHttpException();
+11 −0
Original line number Diff line number Diff line
@@ -9,8 +9,10 @@
use Drupal\Core\Menu\LocalActionManagerInterface;
use Drupal\Core\Plugin\Context\ContextRepositoryInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;

/**
 * Provides a list of block plugins to be added to the layout.
@@ -75,6 +77,15 @@ public function __construct(BlockManagerInterface $block_manager, ContextReposit
   * @return array
   *   A render array as expected by the renderer.
   */
  #[Route(
    path: '/admin/structure/block/library/{theme}',
    name: 'block.admin_library',
    requirements: [
      '_access_theme' => 'TRUE',
      '_permission' => 'administer blocks',
    ],
    defaults: ['_title' => new TranslatableMarkup('Place block')],
  )]
  public function listBlocks(Request $request, $theme) {
    // Since modals do not render any other part of the page, we need to render
    // them manually as part of this listing.
+17 −0
Original line number Diff line number Diff line
@@ -4,8 +4,10 @@

use Drupal\Core\Entity\Controller\EntityListController;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Attribute\Route;

/**
 * Defines a controller to list blocks.
@@ -41,6 +43,21 @@ public function __construct(ThemeHandlerInterface $theme_handler) {
   *   A render array as expected by
   *   \Drupal\Core\Render\RendererInterface::render().
   */
  #[Route(
    path: '/admin/structure/block',
    name: 'block.admin_display',
    requirements: ['_permission' => 'administer blocks'],
    defaults: ['_title' => new TranslatableMarkup('Block layout')],
  )]
  #[Route(
    path: '/admin/structure/block/list/{theme}',
    name: 'block.admin_display_theme',
    requirements: [
      '_access_theme' => 'TRUE',
      '_permission' => 'administer blocks',
    ],
    defaults: ['_title' => new TranslatableMarkup('Block layout')],
  )]
  public function listing($theme = NULL, ?Request $request = NULL) {
    $theme = $theme ?: $this->config('system.theme')->get('default');
    if (!$this->themeHandler->hasUi($theme)) {
Loading