Version 1
[yaffs-website] / web / core / modules / node / src / Plugin / views / area / ListingEmpty.php
1 <?php
2
3 namespace Drupal\node\Plugin\views\area;
4
5 use Drupal\Core\Access\AccessManagerInterface;
6 use Drupal\Core\Url;
7 use Drupal\views\Plugin\views\area\AreaPluginBase;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9
10 /**
11  * Defines an area plugin to display a node/add link.
12  *
13  * @ingroup views_area_handlers
14  *
15  * @ViewsArea("node_listing_empty")
16  */
17 class ListingEmpty extends AreaPluginBase {
18
19   /**
20    * The access manager.
21    *
22    * @var \Drupal\Core\Access\AccessManagerInterface
23    */
24   protected $accessManager;
25
26   /**
27    * Constructs a new ListingEmpty.
28    *
29    * @param array $configuration
30    *   A configuration array containing information about the plugin instance.
31    * @param string $plugin_id
32    *   The plugin ID for the plugin instance.
33    * @param mixed $plugin_definition
34    *   The plugin implementation definition.
35    * @param \Drupal\Core\Access\AccessManagerInterface $access_manager
36    *   The access manager.
37    */
38   public function __construct(array $configuration, $plugin_id, $plugin_definition, AccessManagerInterface $access_manager) {
39     parent::__construct($configuration, $plugin_id, $plugin_definition);
40
41     $this->accessManager = $access_manager;
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
48     return new static(
49       $configuration,
50       $plugin_id,
51       $plugin_definition,
52       $container->get('access_manager')
53     );
54   }
55
56   /**
57    * {@inheritdoc}
58    */
59   public function render($empty = FALSE) {
60     $account = \Drupal::currentUser();
61     if (!$empty || !empty($this->options['empty'])) {
62       $element = [
63         '#theme' => 'links',
64         '#links' => [
65           [
66             'url' => Url::fromRoute('node.add_page'),
67             'title' => $this->t('Add content'),
68           ],
69         ],
70         '#access' => $this->accessManager->checkNamedRoute('node.add_page', [], $account),
71       ];
72       return $element;
73     }
74     return [];
75   }
76
77 }