ListingEmpty.php
Same filename in this branch
Same filename in other branches
- 9 core/modules/node/src/Plugin/views/area/ListingEmpty.php
- 9 core/modules/block_content/src/Plugin/views/area/ListingEmpty.php
- 8.9.x core/modules/node/src/Plugin/views/area/ListingEmpty.php
- 8.9.x core/modules/block_content/src/Plugin/views/area/ListingEmpty.php
- 11.x core/modules/node/src/Plugin/views/area/ListingEmpty.php
- 11.x core/modules/block_content/src/Plugin/views/area/ListingEmpty.php
Namespace
Drupal\node\Plugin\views\areaFile
-
core/
modules/ node/ src/ Plugin/ views/ area/ ListingEmpty.php
View source
<?php
namespace Drupal\node\Plugin\views\area;
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Url;
use Drupal\views\Attribute\ViewsArea;
use Drupal\views\Plugin\views\area\AreaPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines an area plugin to display a node/add link.
*
* @ingroup views_area_handlers
*/
class ListingEmpty extends AreaPluginBase {
/**
* The access manager.
*
* @var \Drupal\Core\Access\AccessManagerInterface
*/
protected $accessManager;
/**
* Constructs a new ListingEmpty.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Access\AccessManagerInterface $access_manager
* The access manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccessManagerInterface $access_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->accessManager = $access_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container->get('access_manager'));
}
/**
* {@inheritdoc}
*/
public function render($empty = FALSE) {
$account = \Drupal::currentUser();
if (!$empty || !empty($this->options['empty'])) {
$element = [
'#theme' => 'links',
'#links' => [
[
'url' => Url::fromRoute('node.add_page'),
'title' => $this->t('Add content'),
],
],
'#access' => $this->accessManager
->checkNamedRoute('node.add_page', [], $account),
];
return $element;
}
return [];
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
ListingEmpty | Defines an area plugin to display a node/add link. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.