StringRangeArgument.php in Views Contextual Range Filter 8
File
src/Plugin/views/argument/StringRangeArgument.php
View source
<?php
namespace Drupal\contextual_range_filter\Plugin\views\argument;
use Drupal\views\Plugin\views\argument\StringArgument;
use Drupal\Core\Form\FormStateInterface;
use Drupal\contextual_range_filter\ContextualRangeFilter;
class StringRangeArgument extends StringArgument {
use MultiRangesTrait;
protected function defineOptions() {
$options = parent::defineOptions();
$options['not'] = [
'default' => FALSE,
'bool' => TRUE,
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['description']['#markup'] = t('Contextual string range filter values are taken from the URL.');
$form['more']['#open'] = TRUE;
$form['break_phrase']['#title'] = t('Allow multiple string (i.e. alphabetic) ranges');
$form['break_phrase']['#description'] = t('If selected, multiple ranges may be specified by stringing them together with plus signs.<br/>Example: <strong>a--f+q--y</strong>');
$form['not'] = [
'#type' => 'checkbox',
'#title' => t('Exclude'),
'#description' => t('Negate the range. If selected, output matching the specified range(s) will be excluded, rather than included.'),
'#default_value' => !empty($this->options['not']),
'#fieldset' => 'more',
];
}
public function query($group_by = FALSE) {
$argument = $this->argument;
if (!empty($this->options['transform_dash'])) {
$argument = strtr($argument, '-', ' ');
}
if (!empty($this->options['break_phrase'])) {
$this
->breakPhraseRange($this->argument);
}
else {
$this->value = [
$argument,
];
}
$this
->ensureMyTable();
if (!empty($this->definition['many to one'])) {
if (!empty($this->options['glossary'])) {
$this->helper->formula = TRUE;
}
$this->helper
->ensureMyTable();
$this->helper
->addFilter();
return;
}
if (empty($this->options['glossary'])) {
$field = "{$this->tableAlias}.{$this->realField}";
}
else {
$field = $this
->getFormula();
}
ContextualRangeFilter::buildRangeQuery($this, $field);
}
}