class AreaPluginBase
Same name and namespace in other branches
- 11.x core/modules/views/src/Plugin/views/area/AreaPluginBase.php \Drupal\views\Plugin\views\area\AreaPluginBase
- 10 core/modules/views/src/Plugin/views/area/AreaPluginBase.php \Drupal\views\Plugin\views\area\AreaPluginBase
- 8.9.x core/modules/views/src/Plugin/views/area/AreaPluginBase.php \Drupal\views\Plugin\views\area\AreaPluginBase
Base class for area handler plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\views\Plugin\views\PluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\views\Plugin\views\HandlerBase implements \Drupal\views\Plugin\views\ViewsHandlerInterface extends \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\area\AreaPluginBase extends \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\HandlerBase implements \Drupal\views\Plugin\views\ViewsHandlerInterface extends \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\PluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of AreaPluginBase
Related topics
4 files declare their use of AreaPluginBase
- DisplayPluginBase.php in core/
modules/ views/ src/ Plugin/ views/ display/ DisplayPluginBase.php - 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\areaView 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.
*/
abstract public 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']);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.