Skip to content
Snippets Groups Projects
Commit 711579f2 authored by Daniel Cothran's avatar Daniel Cothran
Browse files

Issue #3446008 by andileco, nikathone: Fix contextual filters

parent eb0ca06a
No related branches found
Tags 1.0.1
1 merge request!6Update 3 files
Pipeline #208050 passed with warnings
......@@ -3,7 +3,7 @@
namespace Drupal\views_csv_source\Plugin\views\argument;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
use Drupal\views\Plugin\views\argument\StringArgument;
use Drupal\views_csv_source\Plugin\views\ColumnSelectorTrait;
/**
......@@ -13,15 +13,44 @@ use Drupal\views_csv_source\Plugin\views\ColumnSelectorTrait;
*
* @ViewsArgument("views_csv_source_argument")
*/
class ViewsCsvArgument extends ArgumentPluginBase {
class ViewsCsvArgument extends StringArgument {
use ColumnSelectorTrait;
/**
* Build the summary query based on a string.
*/
protected function summaryQuery() {
$this->ensureMyTable();
}
/**
* Add this filter to the query.
*/
public function query($group_by = FALSE) {
$this->query->addFilter($this);
$argument = $this->argument;
if (!empty($this->options['transform_dash'])) {
$argument = strtr($argument, '-', ' ');
}
if (!empty($this->options['break_phrase'])) {
$this->unpackArgumentValue();
}
else {
$this->value = [$argument];
$this->operator = 'or';
}
$this->ensureMyTable();
if (empty($this->options['glossary'])) {
$field = $this->options['key'];
}
if (count($this->value) > 1) {
$argument = $this->value;
}
$this->query->addWhere(0, $field, $argument, '=');
}
/**
......@@ -48,6 +77,7 @@ class ViewsCsvArgument extends ArgumentPluginBase {
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form = $this->buildKeyOptionElement($form);
}
......
<?php
namespace Drupal\views_csv_source\Plugin\views\argument;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
/**
* Base argument handler for views_csv_source.
*
* @ingroup views_argument_handlers
*
* @ViewsArgument("views_csv_source_uri_param")
*/
class ViewsCsvUriParam extends ArgumentPluginBase {
/**
* Add this filter to the query.
*/
public function query($group_by = FALSE) {
$this->query->addUrlParams($this->argument);
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['markup'] = [
'#markup' => $this->t('Add this field to pick the dynamic value from the URL.'),
];
}
}
......@@ -35,14 +35,5 @@ function views_csv_source_views_data() {
],
];
// Contextual filter required to replace the "%" placeholder in the url.
$data['csv']['param'] = [
'title' => t('URL Parameter.'),
'help' => t('Replacement for placeholder in URL.'),
'argument' => [
'id' => 'views_csv_source_uri_param',
],
];
return $data;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment