Views uncovered date filter utilizing "Is between" would not embody finish date

SITUATION:

  • Create a view of transactions (a customized entity in my case, however I do not suppose that is related)
  • Filter in opposition to Authored on (which incorporates each Drupal Developer date and time of creation)
  • Expose Drupal Developer filter
  • Select Operator: Is between
  • Show Drupal Developer view with 10/01/2020 and 10/31/2020 as begin and finish dates for October
  • Notice: I am utilizing Drupal Developer Date Popup module for date entry, which accepts mm/dd/yyyy

PROBLEM:

Transactions on 10/31/2020 are omitted. How can I embody end-date transactions, wanting telling customers to place 11/01/2020 as a substitute of 10/31/2020 (which is what appears pure to them)?

SOLUTION:

Due to @prkos in his reply under {that a} time of 23:59:59 should be included with Drupal Developer finish date to match as much as Drupal Developer final second of Drupal Developer day. After studying this, I added a customized submit perform to Drupal Developer uncovered filter that appends Drupal Developer finish time, like so:

use DrupalCoreFormFormStateInterface;  /**  * Implements hook_form_FORM_ID_alter().  */ perform mymodule_form_views_exposed_form_alter(&$kind, FormStateInterface $form_state, $form_id) {   // Use array_unshift() so customized submit runs earlier than default submit   array_unshift($kind['#submit'], '_my_submit_function'); }  perform _my_submit_function($kind, FormStateInterface $form_state) {   $created = $form_state->getValue('created');   if ($created['max']) {     $created['max'] = $created['max'] . ' 23:59:59';     $form_state->setValue('created', $created);   } } 

Due to @No Sssweat for mentioning in his accepted reply under that array_unshift should be used to make Drupal Developer submit perform run earlier than Drupal Developer default. Initially, I merely used

$kind['#submit'][] = '_my_submit_function'; // Do not do that. It would not work 

See Drupal Developer accepted reply under from @No Sssweat for another technique of fixing Drupal Developer downside utilizing views_query_alter. I attempted this and it labored as nicely, though in Drupal Developer finish I selected Drupal Developer less complicated of Drupal Developer two options.

UPDATE:

Seems that, though Drupal Developer "less complicated" hook_form_alter resolution appeared to work, altering Drupal Developer worth of Drupal Developer filter by including a time breaks Drupal Developer filter when you transfer to a different web page in Drupal Developer checklist as a result of Drupal Developer filter is handed through Drupal Developer question string to Drupal Developer web page and it contains Drupal Developer time, which will not show in Drupal Developer date discipline. Given this, I reverted again to Drupal Developer views_query_alter strategy, which does not have Drupal Developer similar downside. My easy code is

perform mymodule_views_query_alter($view, $question) {   if (!empty($query->the place[1]['conditions'])) {     foreach ($query->the place[1]['conditions'] as $key => &$worth) {       if (strpos($worth['field'], '.created <=')) {         $e = explode(' ', $worth['field']);         $e[2] += (24 * 60 * 60) - 1;         $worth['field'] = implode(' ', $e);       }     }   } } 

Notice that I’ve switched from utilizing IS BETWEEN to utilizing two, separate exams in opposition to Drupal Developer Writer On variable, on with >= and one with <=. You’ll be able to see in Drupal Developer code that I am modifying solely Drupal Developer <= occasion.

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Views uncovered date filter utilizing &quot;Is between&quot; would not embody finish date

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.