Same filename and directory in other branches
- 10 core/modules/block/src/Controller/BlockController.php
- 9 core/modules/block/src/Controller/BlockController.php
Namespace
Drupal\block\Controller
File
core/modules/block/src/Controller/BlockController.php
View source
<?php
namespace Drupal\block\Controller;
use Drupal\Component\Utility\Html;
use Drupal\block\BlockInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class BlockController extends ControllerBase {
protected $themeHandler;
public function __construct(ThemeHandlerInterface $theme_handler) {
$this->themeHandler = $theme_handler;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('theme_handler'));
}
public function performOperation(BlockInterface $block, $op) {
$block
->{$op}()
->save();
$this
->messenger()
->addStatus($this
->t('The block settings have been updated.'));
return $this
->redirect('block.admin_display');
}
public function demo($theme) {
if (!$this->themeHandler
->hasUi($theme)) {
throw new NotFoundHttpException();
}
$page = [
'#title' => Html::escape($this->themeHandler
->getName($theme)),
'#type' => 'page',
'#attached' => [
'drupalSettings' => [
'path' => [
'currentPathIsAdmin' => TRUE,
],
],
'library' => [
'block/drupal.block.admin',
],
],
];
$visible_regions = $this
->getVisibleRegionNames($theme);
foreach (array_keys($visible_regions) as $region) {
$page[$region]['block_description'] = [
'#type' => 'inline_template',
'#template' => '<div class="block-region demo-block">{{ region_name }}</div>',
'#context' => [
'region_name' => $visible_regions[$region],
],
];
}
return $page;
}
protected function getVisibleRegionNames($theme) {
return system_region_list($theme, REGIONS_VISIBLE);
}
}
Classes