3 namespace Drupal\block_content\Plugin\views\area;
5 use Drupal\Core\Access\AccessManagerInterface;
6 use Drupal\Core\Session\AccountInterface;
8 use Drupal\views\Plugin\views\area\AreaPluginBase;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Defines an area plugin to display a block add link.
14 * @ingroup views_area_handlers
16 * @ViewsArea("block_content_listing_empty")
18 class ListingEmpty extends AreaPluginBase {
23 * @var \Drupal\Core\Access\AccessManagerInterface
25 protected $accessManager;
30 * @var \Drupal\Core\Session\AccountInterface
32 protected $currentUser;
35 * Constructs a new ListingEmpty.
37 * @param array $configuration
38 * A configuration array containing information about the plugin instance.
39 * @param string $plugin_id
40 * The plugin ID for the plugin instance.
41 * @param mixed $plugin_definition
42 * The plugin implementation definition.
43 * @param \Drupal\Core\Access\AccessManagerInterface $access_manager
45 * @param \Drupal\Core\Session\AccountInterface $current_user
48 public function __construct(array $configuration, $plugin_id, $plugin_definition, AccessManagerInterface $access_manager, AccountInterface $current_user) {
49 parent::__construct($configuration, $plugin_id, $plugin_definition);
51 $this->accessManager = $access_manager;
52 $this->currentUser = $current_user;
58 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
63 $container->get('access_manager'),
64 $container->get('current_user')
71 public function render($empty = FALSE) {
72 if (!$empty || !empty($this->options['empty'])) {
73 /** @var \Drupal\Core\Access\AccessResultInterface|\Drupal\Core\Cache\CacheableDependencyInterface $access_result */
74 $access_result = $this->accessManager->checkNamedRoute('block_content.add_page', [], $this->currentUser, TRUE);
76 '#markup' => $this->t('Add a <a href=":url">custom block</a>.', [':url' => Url::fromRoute('block_content.add_page')->toString()]),
77 '#access' => $access_result->isAllowed(),
79 'contexts' => $access_result->getCacheContexts(),
80 'tags' => $access_result->getCacheTags(),
81 'max-age' => $access_result->getCacheMaxAge(),