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.