Last active
July 20, 2024 10:00
-
-
Save esolitos/dba880ba0a71d19f8d39c6dd37f0bbdc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! This saved my day!