Skip to content

Instantly share code, notes, and snippets.

@levmyshkin
Created November 19, 2021 14:20
Show Gist options
  • Save levmyshkin/13b5724137fbd6a220052b73a12ae4a5 to your computer and use it in GitHub Desktop.
Save levmyshkin/13b5724137fbd6a220052b73a12ae4a5 to your computer and use it in GitHub Desktop.
Extending custom Drupal Views filter handler
<?php
namespace Drupal\did_this_help\Plugin\views\filter;
use Drupal\views\Plugin\views\filter\InOperator;
/**
* Filters by given list of yes/no options.
*
* @ingroup views_filter_handlers
*
* @ViewsFilter("did_this_help")
*/
class DidThisHelp extends InOperator {
/**
* {@inheritdoc}
*/
public function getValueOptions() {
if (isset($this->valueOptions)) {
return $this->valueOptions;
}
$this->valueOptions = [
'yes' => $this->t('Yes'),
'no' => $this->t('No'),
];
return $this->valueOptions;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment