Problem/Motivation

Smart date module date views filter plugin adds granularity to be able to filter by year. The Smart Date plugin (which I think it is wrongly named "date") collides with this module's plugindate_with_more_options, and as a result there is no way for using the granularity provided for the Smart Date module in a views filter.

Steps to reproduce

  • Install both, Smart Date module and Views Year Filter
  • Create a content type and add a smart date field
  • Create a view filtering by, for example, Date start
  • At this point there will be no options for granularity
  • Save the view and try to filter by the content's year
  • No results will be shown

Proposed resolution

Since changing the smart date functionality will be more tedious, as a workaround I propose to check the provider in this module's hook views_year_filter_views_plugins_filter_alter, and avoid the ViewsYearFilterDate implementation if the provider is the smart_date.

function views_year_filter_views_plugins_filter_alter(&$info) {
  if (isset($info['date']) && $info['date']['provider'] != 'smart_date') {
    $info['date']['class'] = ViewsYearFilterDate::class;
  }
  if (isset($info['datetime'])) {
    $info['datetime']['class'] = ViewsYearFilterDatetime::class;
  }
  if (isset($info['search_api_date']) && \Drupal::moduleHandler()->moduleExists('search_api')) {
    $info['search_api_date']['class'] = ViewsSearchApiYearFilterDate::class;
  }
}

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tuwebo created an issue. See original summary.

tuwebo’s picture

Status: Active » Needs review

I've added the mentioned provider's check. Any review is more than welcome.

berramou made their first commit to this issue’s fork.

berramou’s picture

Hello @tuwebo,
thank you for reporting this issue and for the merge request.
Yes you are right both modules implements hook_views_plugins_filter_alter and my module has bigger weight so it comes after smart_date module, and override the used class for filter Date plugin.

Your code is working since the smart_date has year granularity which provide the same feature, i let it set it's plugin class instead of this module class.

  • berramou committed cf0126e2 on 2.0.x authored by tuwebo
    Issue #3559207: Allow granularity options for the smart_date module
    
berramou’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

berramou’s picture

Status: Fixed » Closed (fixed)
tuwebo’s picture

Hello @berramou,
Thank you very much for the fast response and the review.
I think we should implement the getProvider() method in the classes:

  • ViewsYearFilterDatetime
  • ViewsYearFilterDate
  • ViewsSearchApiYearFilterDate

Since using the hook views_year_filter_views_plugins_filter_alter for doing so seems to have no effect if we call it in another views filter plugin. E.g. $filter->getProvider(); will return the original one instead.
I've created another branch for it, and I'll post the changes as soon as possible.

berramou’s picture

Hello @tuwebo
Thank you for you contribution, yes you are right that's proper way to set the provider.
I will review and test you MR when i have some time!