Broken.php in Drupal 10
File
core/lib/Drupal/Core/Block/Plugin/Block/Broken.php
View source
<?php
namespace Drupal\Core\Block\Plugin\Block;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Block\BlockPluginTrait;
use Drupal\Core\Cache\CacheableDependencyTrait;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Broken extends PluginBase implements BlockPluginInterface, ContainerFactoryPluginInterface {
use BlockPluginTrait;
use CacheableDependencyTrait;
protected $currentUser;
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountInterface $current_user) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentUser = $current_user;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('current_user'));
}
public function build() {
$build = [];
if ($this->currentUser
->hasPermission('administer blocks')) {
$build += $this
->brokenMessage();
}
return $build;
}
public function blockForm($form, FormStateInterface $form_state) {
return $this
->brokenMessage();
}
protected function brokenMessage() {
$build['message'] = [
'#markup' => $this
->t('This block is broken or missing. You may be missing content or you might need to enable the original module.'),
];
return $build;
}
}
Classes
Name |
Description |
Broken |
Defines a fallback plugin for missing block plugins. |