MaestroEngineTemplateFilter.php in Maestro 8.2
File
src/Plugin/views/filter/MaestroEngineTemplateFilter.php
View source
<?php
namespace Drupal\maestro\Plugin\views\filter;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ViewExecutable;
use Drupal\maestro\Engine\MaestroEngine;
use Drupal\views\Plugin\views\filter\InOperator;
class MaestroEngineTemplateFilter extends InOperator {
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$this->valueTitle = $this
->t('Templates to Filter On');
$this->definition['options callback'] = [
$this,
'generateTemplateOptions',
];
}
public function query() {
if (!empty($this->value) && current($this->value) != '0') {
parent::query();
}
}
public function validate() {
if (!empty($this->value)) {
parent::validate();
}
}
protected function generateTemplateOptions() {
$templates = MaestroEngine::getTemplates();
$options = [];
$options[0] = $this
->t(' - Any -');
foreach ($templates as $machine_name => $template) {
$options[$machine_name] = $template->label;
}
return $options;
}
}