public function BlockPermissionsBlockLibraryController::listBlocks in Block permissions 8
Shows a list of blocks that can be added to a theme's layout.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The current request.
string $theme: Theme key of the block list.
Return value
array A render array as expected by the renderer.
Overrides BlockLibraryController::listBlocks
File
- src/
Controller/ BlockPermissionsBlockLibraryController.php, line 16
Class
- BlockPermissionsBlockLibraryController
- Controller for changes in the BlockLibraryController.
Namespace
Drupal\block_permissions\ControllerCode
public function listBlocks(Request $request, $theme) {
// First build the list.
$build = parent::listBlocks($request, $theme);
// Iterate over the rows and validate each plugin.
foreach ($build['blocks']['#rows'] as $key => $row) {
if (!empty($row['operations']['data']['#links']['add']['url'])) {
// Get the plugin via the add URL (there is no other way..).
$url = $row['operations']['data']['#links']['add']['url'];
if (!$url
->access()) {
unset($build['blocks']['#rows'][$key]);
}
}
}
return $build;
}