Over in #2600442: Add support for Facet Api in Drupal 8 a new query type is being added to use dates.
This issue adds a widget that can use that newly added query type to make dates pretty.

Comments

borisson_ created an issue. See original summary.

borisson_’s picture

StatusFileSize
new2.82 KB

This patch is not empty.

borisson_’s picture

borisson_’s picture

This needs a test as well, but first we need to get #2611812: Create a date query type in before work on this can go on.

strykaizer’s picture

Version: » 8.x-1.x-dev
strykaizer’s picture

jespermb’s picture

StatusFileSize
new11.3 KB
new8.12 KB

Hi, I have been working on this a bit since drupalcon dublin, its not done yet but I thought I would share my progress. The filters for -1 day, -1 month and -1 year works but the custom range is not yet ready. I am looking into making something similar to what Google does, but to begin with it might be fine to have 2 text fields.

I just updated my work with the latest patch from https://www.drupal.org/node/2611812

If someone want to have a look and advise if i am going in the right direktion it would be welcome. :)

borisson_’s picture

Status: Postponed » Needs review

Back to active, the query type is committed. Haven't reviewed #7 yet, but I'm assuming it'll need a reroll. Setting to needs review to remind myself to do the actual review.

The last submitted patch, 2: date-widget.patch, failed testing.

borisson_’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Patch still applies, is in both the new "facets" as well as the very old "facetapi" namespaces.
We'll also need tests. Architecturally this looks solid though.

borisson_’s picture

At the very least - there should be a unit test per widget added here that extends WidgetTestBase once that's added from #2838236: Add widget unit test base + basic coverage for all widgets.

yeebot’s picture

I've tested the patch from #7 against 8.x-1.0-alpha7 and it worked for me although when I attempted to save a date range widget facet I got the following 500 error:

PHP message: PHP Fatal error: Declaration of Drupal\facets\Plugin\facets\widget\DateBasicWidget::getQueryType($query_types) must be compatible with Drupal\facets\Widget\WidgetPluginInterface::getQueryType(array $query_types) in /home/vagrant/shared/csp-d8/web/modules/contrib/facets/src/Plugin/facets/widget/DateBasicWidget.php on line 20

I managed to fix this after applying the same changes as seen in the patch from #4 from https://www.drupal.org/node/2838234. to facets/src/Plugin/facets/widget/DateRangeWidget.php i.e.

-  public function getQueryType($query_types) {
+  public function getQueryType(array $query_types) {
jespermb’s picture

Thanks for the update. I will try to get that in this weekend and create a test for the widget. :)

borisson_’s picture

Adding the test should probably be easier with the new base class, a unit test that extends \Drupal\Tests\facets\Unit\Plugin\widget\WidgetTestBase should be a good start. Have a look at \Drupal\Tests\facets\Unit\Plugin\widget\NumericGranularWidgetTest as an example.

Thanks for your continued work on this @jespermb!

jespermb’s picture

Assigned: Unassigned » jespermb
Status: Needs work » Needs review
StatusFileSize
new9.34 KB

I have updated the patch so it applies to the latest dev and I created a basic test. I was wondering what to include in the test? Do you have any suggestions on what should be tested? I am working on a form for the custom time selection and I think i have a solution which i will try to include soon.

borisson_’s picture

I think this is a good start and we can probably commit this patch and improve the tests as new bug reports trickle in. Going to ask @ekes for a review of this one.

acbramley’s picture

Status: Needs review » Needs work

In my testing this isn't really functional at the moment. All I get is a list of 3 links "Last day", "Last month", "Last year" with no select options for from/to dates. Selecting an option does filter the results correctly but doesn't show any way to remove the filter (e.g the (-) sign in front of the link).

Small code review:

+++ b/src/Plugin/facets/widget/DateRangeWidget.php
@@ -0,0 +1,135 @@
+          '#date_timezone' => 'America/Chicago',

Need to use the site/user timezone here.

edysmp’s picture

<form method="post" accept-charset="UTF-8" data-drupal-form-fields="" lpformnum="1">
  
</form>

The form is rendering empty.

dennis cohn’s picture

Nice one! Applied patch #15 with succes.

With the date range you've only got dates from the past:
'Last day', Last month' & 'Last year'.
But when you've got an events view (for example), you want to have facets with dates in the future.
Can we makes this configurable? Or do we need to make another 'relative date selection'

borisson_’s picture

Status: Needs work » Closed (outdated)

Closing this issue in favor of #2896229: move date handling to a processor, so date facets can use existing widgets, as that makes this issue redundant.