Definition of Drupal\views\Plugin\views\area\AreaPluginBase.
<?php
/**
* @file
* Definition of Drupal\views\Plugin\views\area\AreaPluginBase.
*/
namespace Drupal\views\Plugin\views\area;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\PluginBase;
use Drupal\views\Plugin\views\HandlerBase;
/**
* @defgroup views_area_handlers Views area handlers
* @{
* Handlers to tell Views what can display in header, footer
* and empty text in a view.
*/
/**
* Base class for area handlers.
*
* @ingroup views_area_handlers
*/
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;
}
}
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'] = array(
'default' => FALSE,
'bool' => TRUE,
);
return $options;
}
/**
* Provide extra data to the administration form
*/
public function adminSummary() {
return $this
->adminLabel();
}
/**
* Default options form that provides the label widget that all fields
* should have.
*/
public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
if ($form_state['type'] != 'empty') {
$form['empty'] = array(
'#type' => 'checkbox',
'#title' => t('Display even if view has no result'),
'#default_value' => isset($this->options['empty']) ? $this->options['empty'] : 0,
);
}
}
/**
* Don't run a query
*/
public function query() {
}
/**
* 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);
/**
* Area handlers shouldn't have groupby.
*/
public function usesGroupBy() {
return FALSE;
}
}
/**
* @}
*/
Name | Description |
---|---|
AreaPluginBase | Base class for area handlers. |