You are here

class ListingEmpty in Drupal 10

Same name in this branch
  1. 10 core/modules/node/src/Plugin/views/area/ListingEmpty.php \Drupal\node\Plugin\views\area\ListingEmpty
  2. 10 core/modules/block_content/src/Plugin/views/area/ListingEmpty.php \Drupal\block_content\Plugin\views\area\ListingEmpty
Same name and namespace in other branches
  1. 8 core/modules/block_content/src/Plugin/views/area/ListingEmpty.php \Drupal\block_content\Plugin\views\area\ListingEmpty
  2. 9 core/modules/block_content/src/Plugin/views/area/ListingEmpty.php \Drupal\block_content\Plugin\views\area\ListingEmpty

Defines an area plugin to display a block add link.

Plugin annotation

@ViewsArea("block_content_listing_empty");

Hierarchy

  • class \Drupal\views\Plugin\views\area\AreaPluginBase extends \Drupal\views\Plugin\views\HandlerBase

Expanded class hierarchy of ListingEmpty

Related topics

File

core/modules/block_content/src/Plugin/views/area/ListingEmpty.php, line 18

Namespace

Drupal\block_content\Plugin\views\area
View source
class ListingEmpty extends AreaPluginBase {

  /**
   * The access manager.
   *
   * @var \Drupal\Core\Access\AccessManagerInterface
   */
  protected $accessManager;

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;

  /**
   * 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.
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   The current user.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, AccessManagerInterface $access_manager, AccountInterface $current_user) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->accessManager = $access_manager;
    $this->currentUser = $current_user;
  }

  /**
   * {@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'), $container
      ->get('current_user'));
  }

  /**
   * {@inheritdoc}
   */
  public function render($empty = FALSE) {
    if (!$empty || !empty($this->options['empty'])) {

      /** @var \Drupal\Core\Access\AccessResultInterface|\Drupal\Core\Cache\CacheableDependencyInterface $access_result */
      $access_result = $this->accessManager
        ->checkNamedRoute('block_content.add_page', [], $this->currentUser, TRUE);
      $element = [
        '#markup' => $this
          ->t('Add a <a href=":url">custom block</a>.', [
          ':url' => Url::fromRoute('block_content.add_page')
            ->toString(),
        ]),
        '#access' => $access_result
          ->isAllowed(),
        '#cache' => [
          'contexts' => $access_result
            ->getCacheContexts(),
          'tags' => $access_result
            ->getCacheTags(),
          'max-age' => $access_result
            ->getCacheMaxAge(),
        ],
      ];
      return $element;
    }
    return [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AreaPluginBase::$areaType public property The type of this area handler, i.e. 'header', 'footer', or 'empty'.
AreaPluginBase::adminSummary public function
AreaPluginBase::buildOptionsForm public function 7
AreaPluginBase::defineOptions protected function 8
AreaPluginBase::init public function Overrides Drupal\views\Plugin\views\HandlerBase::init(). 1
AreaPluginBase::isEmpty public function Does that area have nothing to show. 1
AreaPluginBase::preRender public function Performs any operations needed before full rendering. 1
AreaPluginBase::usesGroupBy public function
ListingEmpty::$accessManager protected property The access manager.
ListingEmpty::$currentUser protected property The current user.
ListingEmpty::create public static function
ListingEmpty::render public function Render the area. Overrides AreaPluginBase::render
ListingEmpty::__construct public function Constructs a new ListingEmpty.