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
Issue fork views_year_filter-3559207
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
Comment #3
tuwebo commentedI've added the mentioned provider's check. Any review is more than welcome.
Comment #5
berramou commentedHello @tuwebo,
thank you for reporting this issue and for the merge request.
Yes you are right both modules implements
hook_views_plugins_filter_alterand 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.
Comment #7
berramou commentedComment #9
berramou commentedComment #10
tuwebo commentedHello @berramou,
Thank you very much for the fast response and the review.
I think we should implement the
getProvider()method in the classes:Since using the hook
views_year_filter_views_plugins_filter_alterfor 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.
Comment #12
berramou commentedHello @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!