3 namespace Drupal\views\Plugin\views\area;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\ViewExecutable;
7 use Drupal\views\Plugin\views\display\DisplayPluginBase;
8 use Drupal\views\Plugin\views\HandlerBase;
11 * @defgroup views_area_handlers Views area handler plugins
13 * Plugins governing areas of views, such as header, footer, and empty text.
15 * Area handler plugins extend \Drupal\views\Plugin\views\area\AreaPluginBase.
16 * They must be annotated with \Drupal\views\Annotation\ViewsArea annotation,
17 * and they must be in namespace directory Plugin\views\area.
19 * @ingroup views_plugins
24 * Base class for area handler plugins.
26 abstract class AreaPluginBase extends HandlerBase {
29 * The type of this area handler, i.e. 'header', 'footer', or 'empty'.
36 * Overrides Drupal\views\Plugin\views\HandlerBase::init().
38 * Make sure that no result area handlers are set to be shown when the result
41 public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
42 parent::init($view, $display, $options);
44 if ($this->areaType == 'empty') {
45 $this->options['empty'] = TRUE;
52 public function usesGroupBy() {
59 protected function defineOptions() {
60 $options = parent::defineOptions();
62 $this->definition['field'] = !empty($this->definition['field']) ? $this->definition['field'] : '';
63 $label = !empty($this->definition['label']) ? $this->definition['label'] : $this->definition['field'];
64 $options['admin_label']['default'] = $label;
65 $options['empty'] = ['default' => FALSE];
73 public function adminSummary() {
74 return $this->adminLabel();
80 public function buildOptionsForm(&$form, FormStateInterface $form_state) {
81 parent::buildOptionsForm($form, $form_state);
83 if ($form_state->get('type') != 'empty') {
85 '#type' => 'checkbox',
86 '#title' => $this->t('Display even if view has no result'),
87 '#default_value' => isset($this->options['empty']) ? $this->options['empty'] : 0,
93 * Performs any operations needed before full rendering.
95 * @param array $results
96 * The results of the view.
98 public function preRender(array $results) {
105 * (optional) Indicator if view result is empty or not. Defaults to FALSE.
108 * In any case we need a valid Drupal render array to return.
110 public abstract function render($empty = FALSE);
113 * Does that area have nothing to show.
115 * This method should be overridden by more complex handlers where the output
116 * is not static and maybe itself be empty if it's rendered.
119 * Return TRUE if the area is empty, else FALSE.
121 public function isEmpty() {
122 return empty($this->options['empty']);