You are here

public function ListingEmpty::render in Zircon Profile 8

Same name in this branch
  1. 8 core/modules/node/src/Plugin/views/area/ListingEmpty.php \Drupal\node\Plugin\views\area\ListingEmpty::render()
  2. 8 core/modules/block_content/src/Plugin/views/area/ListingEmpty.php \Drupal\block_content\Plugin\views\area\ListingEmpty::render()
Same name and namespace in other branches
  1. 8.0 core/modules/block_content/src/Plugin/views/area/ListingEmpty.php \Drupal\block_content\Plugin\views\area\ListingEmpty::render()

Render the area.

Parameters

bool $empty: (optional) Indicator if view result is empty or not. Defaults to FALSE.

Return value

array In any case we need a valid Drupal render array to return.

Overrides AreaPluginBase::render

File

core/modules/block_content/src/Plugin/views/area/ListingEmpty.php, line 76
Contains \Drupal\block_content\Plugin\views\area\ListingEmpty.

Class

ListingEmpty
Defines an area plugin to display a block add link.

Namespace

Drupal\block_content\Plugin\views\area

Code

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', array(), $this->currentUser, TRUE);
    $element = array(
      '#markup' => $this
        ->t('Add a <a href=":url">custom block</a>.', array(
        ':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 array();
}