Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Implements hook_views_data_alter().
- */
- function my_module_views_data_alter(array &$data) {
- $data['node__profile_birthday']['birthday'] = [
- 'title' => t('Filter by birthday'),
- 'group' => t('Content'),
- 'help' => t('Filter profiles by birthday.'),
- 'filter' => [
- 'id' => 'birthday',
- 'field' => 'profile_birthday_value'
- ],
- ];
- }
- <?php
- namespace Drupalmy_modulePluginviewsfilter;
- use DrupalviewsPluginviewsfilterNumericFilter;
- /**
- * Basic filter handler for Birthdays.
- *
- * @ViewsFilter("birthday")
- */
- class Birthday extends NumericFilter {
- /**
- * Override the original Views opBetween behavior.
- */
- protected function opBetween($field) {
- // The birthdate is between -3 days and +7 days from the current date
- $expression = "DAYOFYEAR($field) BETWEEN ((DAYOFYEAR(CURRENT_DATE())) - 3) AND ((DAYOFYEAR(CURRENT_DATE())) + 7)";
- $this->query->addWhereExpression($this->options['group'], $expression);
- }
- }
Add Comment
Please, Sign In to add comment