Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
a82ea10b
Commit
a82ea10b
authored
Jun 19, 2013
by
alexpott
Browse files
Issue
#1987638
by vijaycs85, manu4543: Convert block_admin_display() to a new style controller.
parent
16c9b52d
Changes
8
Hide whitespace changes
Inline
Side-by-side
core/modules/block/block.admin.inc
View file @
a82ea10b
...
...
@@ -21,23 +21,6 @@ function block_admin_demo($theme = NULL) {
);
}
/**
* Page callback: Shows the block administration page.
*
* @param string $theme
* The theme to display the administration page for.
*
* @return array
* A render array for a page containing a list of blocks.
*
* @see block_menu()
*/
function
block_admin_display
(
$theme
)
{
return
Drupal
::
entityManager
()
->
getListController
(
'block'
)
->
render
(
$theme
);
}
/**
* Page callback: Build the block instance add form.
*
...
...
core/modules/block/block.module
View file @
a82ea10b
...
...
@@ -117,10 +117,7 @@ function block_menu() {
$items
[
'admin/structure/block'
]
=
array
(
'title'
=>
'Blocks'
,
'description'
=>
'Configure what block content appears in your site\'s sidebars and other regions.'
,
'page callback'
=>
'block_admin_display'
,
'page arguments'
=>
array
(
$default_theme
),
'access arguments'
=>
array
(
'administer blocks'
),
'file'
=>
'block.admin.inc'
,
'route_name'
=>
'block_admin_display'
,
);
$items
[
'admin/structure/block/add/%/%'
]
=
array
(
'title'
=>
'Configure block'
,
...
...
@@ -160,11 +157,8 @@ function block_menu() {
$theme
=
$themes
[
$key
];
$items
[
'admin/structure/block/list/'
.
$plugin_id
]
=
array
(
'title'
=>
check_plain
(
$theme
->
info
[
'name'
]),
'page arguments'
=>
array
(
$key
),
'type'
=>
$key
==
$default_theme
?
MENU_DEFAULT_LOCAL_TASK
:
MENU_LOCAL_TASK
,
'access callback'
=>
'_block_themes_access'
,
'access arguments'
=>
array
(
$key
),
'file'
=>
'block.admin.inc'
,
'route_name'
=>
'block_admin_display.'
.
$plugin_id
);
$items
[
'admin/structure/block/demo/'
.
$key
]
=
array
(
'title'
=>
check_plain
(
$theme
->
info
[
'name'
]),
...
...
core/modules/block/block.routing.yml
View file @
a82ea10b
...
...
@@ -4,3 +4,11 @@ block_admin_block_delete:
_entity_form
:
'
block.delete'
requirements
:
_permission
:
'
administer
blocks'
block_admin_display
:
pattern
:
'
/admin/structure/block'
defaults
:
_content
:
'
\Drupal\block\Controller\BlockListController::listing'
entity_type
:
'
block'
requirements
:
_permission
:
'
administer
blocks'
core/modules/block/block.services.yml
View file @
a82ea10b
...
...
@@ -9,3 +9,12 @@ services:
factory_method
:
get
factory_service
:
cache_factory
arguments
:
[
block
]
block.route_subscriber
:
class
:
Drupal\block\Routing\RouteSubscriber
tags
:
-
{
name
:
event_subscriber
}
arguments
:
[
'
@plugin.manager.system.plugin_ui'
]
block.theme_access_check
:
class
:
Drupal\block\Access\BlockThemeAccessCheck
tags
:
-
{
name
:
access_check
}
core/modules/block/lib/Drupal/block/Access/BlockThemeAccessCheck.php
0 → 100644
View file @
a82ea10b
<?php
/**
* @file
* Contains \Drupal\block\Access\BlockThemeAccessCheck.
*/
namespace
Drupal\block\Access
;
use
Drupal\Core\Access\AccessCheckInterface
;
use
Symfony\Component\Routing\Route
;
use
Symfony\Component\HttpFoundation\Request
;
/**
* Checks access for displaying block page.
*/
class
BlockThemeAccessCheck
implements
AccessCheckInterface
{
/**
* {@inheritdoc}
*/
public
function
applies
(
Route
$route
)
{
return
array_key_exists
(
'_block_themes_access'
,
$route
->
getRequirements
());
}
/**
* {@inheritdoc}
*/
public
function
access
(
Route
$route
,
Request
$request
)
{
$theme
=
$request
->
attributes
->
get
(
'theme'
);
return
user_access
(
'administer blocks'
)
&&
drupal_theme_access
(
$theme
);
}
}
core/modules/block/lib/Drupal/block/Controller/BlockListController.php
0 → 100644
View file @
a82ea10b
<?php
/**
* @file
* Contains \Drupal\block\Controller\BlockListController.
*/
namespace
Drupal\block\Controller
;
use
Drupal\Core\Entity\Controller\EntityListController
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Drupal\Core\Config\ConfigFactory
;
use
Drupal\Core\Entity\EntityManager
;
/**
* Defines a controller to list blocks.
*/
class
BlockListController
extends
EntityListController
{
/**
* The configuration factory object.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected
$configFactory
;
/**
* Creates an BlockListController object.
*
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager.
* @param \Drupal\Core\Config\ConfigFactory $config_factory
* Configuration factory object.
*/
public
function
__construct
(
EntityManager
$entity_manager
,
ConfigFactory
$config_factory
)
{
$this
->
entityManager
=
$entity_manager
;
$this
->
configFactory
=
$config_factory
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'plugin.manager.entity'
),
$container
->
get
(
'config.factory'
)
);
}
/**
* Shows the block administration page.
*
* @param string $entity_type
* Entity type of list page.
* @param string|null $theme
* Theme key of block list.
*
* @return array
* A render array as expected by drupal_render().
*/
public
function
listing
(
$entity_type
,
$theme
=
NULL
)
{
$default_theme
=
$theme
?:
$this
->
configFactory
->
get
(
'system.theme'
)
->
get
(
'default'
);
return
$this
->
entityManager
->
getListController
(
$entity_type
)
->
render
(
$default_theme
);
}
}
core/modules/block/lib/Drupal/block/Routing/RouteSubscriber.php
0 → 100644
View file @
a82ea10b
<?php
/**
* @file
* Contains \Drupal\block\Routing\RouteSubscriber.
*/
namespace
Drupal\block\Routing
;
use
Drupal\Core\Routing\RouteBuildEvent
;
use
Drupal\Core\Routing\RoutingEvents
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
use
Symfony\Component\Routing\Route
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Drupal\Component\Plugin\PluginManagerInterface
;
/**
* Listens to the dynamic route events.
*/
class
RouteSubscriber
implements
EventSubscriberInterface
{
/**
* The injection plugin manager that should be passed into the route.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected
$pluginManager
;
/**
* Constructs a RouteSubscriber object.
*
* @param \Drupal\Component\Plugin\PluginManagerInterface $plugin_manager
* The service container this object should use.
*/
public
function
__construct
(
PluginManagerInterface
$plugin_manager
)
{
$this
->
pluginManager
=
$plugin_manager
;
}
/**
* Implements EventSubscriberInterface::getSubscribedEvents().
*/
public
static
function
getSubscribedEvents
()
{
$events
[
RoutingEvents
::
DYNAMIC
]
=
'routes'
;
return
$events
;
}
/**
* Generate dynamic routes for various block pages.
*
* @param \Drupal\Core\Routing\RouteBuildEvent $event
* The route building event.
*
* @return \Symfony\Component\Routing\RouteCollection
* The route collection that contains the new dynamic route.
*/
public
function
routes
(
RouteBuildEvent
$event
)
{
$collection
=
$event
->
getRouteCollection
();
foreach
(
$this
->
pluginManager
->
getDefinitions
()
as
$plugin_id
=>
$plugin
)
{
list
(
$plugin_base
,
$key
)
=
explode
(
':'
,
$plugin_id
);
if
(
$plugin_base
==
'block_plugin_ui'
)
{
$route
=
new
Route
(
'admin/structure/block/list/'
.
$plugin_id
,
array
(
'_controller'
=>
'\Drupal\block\Controller\BlockListController::listing'
,
'entity_type'
=>
'block'
,
'theme'
=>
$key
,
),
array
(
'_block_themes_access'
=>
'TRUE'
,
));
$collection
->
add
(
'block_admin_display.'
.
$plugin_id
,
$route
);
}
}
}
}
core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php
View file @
a82ea10b
...
...
@@ -27,7 +27,7 @@ class BlockStorageUnitTest extends DrupalUnitTestBase {
*
* @var array
*/
public
static
$modules
=
array
(
'block'
,
'block_test'
);
public
static
$modules
=
array
(
'block'
,
'block_test'
,
'system'
);
/**
* The block storage controller.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment