You are here

abstract class AreaPluginBase in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/area/AreaPluginBase.php \Drupal\views\Plugin\views\area\AreaPluginBase
  2. 9 core/modules/views/src/Plugin/views/area/AreaPluginBase.php \Drupal\views\Plugin\views\area\AreaPluginBase

Base class for area handler plugins.

Hierarchy

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

Expanded class hierarchy of AreaPluginBase

Related topics

3 files declare their use of AreaPluginBase
ListingEmpty.php in core/modules/node/src/Plugin/views/area/ListingEmpty.php
ListingEmpty.php in core/modules/block_content/src/Plugin/views/area/ListingEmpty.php
TestExample.php in core/modules/views/tests/modules/views_test_data/src/Plugin/views/area/TestExample.php

File

core/modules/views/src/Plugin/views/area/AreaPluginBase.php, line 26

Namespace

Drupal\views\Plugin\views\area
View source
abstract class AreaPluginBase extends HandlerBase {

  /**
   * The type of this area handler, i.e. 'header', 'footer', or 'empty'.
   *
   * @var string
   */
  public $areaType;

  /**
   * Overrides Drupal\views\Plugin\views\HandlerBase::init().
   *
   * Make sure that no result area handlers are set to be shown when the result
   * is empty.
   */
  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
    parent::init($view, $display, $options);
    if ($this->areaType == 'empty') {
      $this->options['empty'] = TRUE;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function usesGroupBy() {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $this->definition['field'] = !empty($this->definition['field']) ? $this->definition['field'] : '';
    $label = !empty($this->definition['label']) ? $this->definition['label'] : $this->definition['field'];
    $options['admin_label']['default'] = $label;
    $options['empty'] = [
      'default' => FALSE,
    ];
    return $options;
  }

  /**
   * {@inheritdoc}
   */
  public function adminSummary() {
    return $this
      ->adminLabel();
  }

  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    if ($form_state
      ->get('type') != 'empty') {
      $form['empty'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Display even if view has no result'),
        '#default_value' => $this->options['empty'] ?? 0,
      ];
    }
  }

  /**
   * Performs any operations needed before full rendering.
   *
   * @param array $results
   *   The results of the view.
   */
  public function preRender(array $results) {
  }

  /**
   * Render the area.
   *
   * @param bool $empty
   *   (optional) Indicator if view result is empty or not. Defaults to FALSE.
   *
   * @return array
   *   In any case we need a valid Drupal render array to return.
   */
  public abstract function render($empty = FALSE);

  /**
   * Does that area have nothing to show.
   *
   * This method should be overridden by more complex handlers where the output
   * is not static and maybe itself be empty if it's rendered.
   *
   * @return bool
   *   Return TRUE if the area is empty, else FALSE.
   */
  public function isEmpty() {
    return empty($this->options['empty']);
  }

}

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::render abstract public function Render the area. 13
AreaPluginBase::usesGroupBy public function