Guest User

Untitled

a guest
Mar 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Implements hook_views_data_alter().
  5. */
  6. function my_module_views_data_alter(array &$data) {
  7. $data['node__profile_birthday']['birthday'] = [
  8. 'title' => t('Filter by birthday'),
  9. 'group' => t('Content'),
  10. 'help' => t('Filter profiles by birthday.'),
  11. 'filter' => [
  12. 'id' => 'birthday',
  13. 'field' => 'profile_birthday_value'
  14. ],
  15. ];
  16. }
  17.  
  18. <?php
  19.  
  20. namespace Drupalmy_modulePluginviewsfilter;
  21.  
  22. use DrupalviewsPluginviewsfilterNumericFilter;
  23.  
  24.  
  25. /**
  26. * Basic filter handler for Birthdays.
  27. *
  28. * @ViewsFilter("birthday")
  29. */
  30. class Birthday extends NumericFilter {
  31. /**
  32. * Override the original Views opBetween behavior.
  33. */
  34. protected function opBetween($field) {
  35. // The birthdate is between -3 days and +7 days from the current date
  36. $expression = "DAYOFYEAR($field) BETWEEN ((DAYOFYEAR(CURRENT_DATE())) - 3) AND ((DAYOFYEAR(CURRENT_DATE())) + 7)";
  37.  
  38. $this->query->addWhereExpression($this->options['group'], $expression);
  39.  
  40. }
  41.  
  42. }
Add Comment
Please, Sign In to add comment