Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@esolitos
Last active March 28, 2023 08:10
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esolitos/dba880ba0a71d19f8d39c6dd37f0bbdc to your computer and use it in GitHub Desktop.
Save esolitos/dba880ba0a71d19f8d39c6dd37f0bbdc to your computer and use it in GitHub Desktop.
# Schema for the views plugins.
views.filter.project_size_range_select:
type: views_filter
label: 'Foobar numeric'
views.filter_value.project_size_range_select:
type: views.filter_value.numeric
label: 'Foobar Numeric'
<?php
/**
* Implements hook_views_data_alter().
*/
function foobar_views_data_alter(array &$data) {
// Clone an existing "numeric" field
$data['node__field_a']['field_a_value_range'] = $data['node__a']['field_a_value'];
// Change the title (otherwise it's indistinguishable in the UI
$data['node__field_a']['field_a_value_range']['title'] = t("Foobar");
// Set the correct filter ID for this field.
$data['node__field_a']['field_a_value_range']['filter']['id'] = 'project_size_range_select';
// Remove unused plugins for the cloned field.
unset($data['node__field_a']['field_a_value_range']['field']);
unset($data['node__field_a']['field_a_value_range']['argument']);
return $data;
}
<?php
namespace Drupal\foobar\Plugin\views\filter;
use Drupal\views\Plugin\views\filter\NumericFilter;
/**
* Class DateYearFilter
*
* @ingroup views_filter_handlers
*
* @ViewsFilter("project_size_range_select")
*/
class FoobarProjectSizeRangeSelectionFilter extends NumericFilter {
}
@jlbellido
Copy link

Thanks! This saved my day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment