- Merge request !14Issue #3096023: Add option to limit calendar navigation (infinite pages!) β (Open) created by Unnamed author
- π©πͺGermany 4kant
In Drupal 7 we could limit navigation this way:
- filter (limit) nodes by a relevant date field (e.g. < +14 days)
- in navigation: choose "Page by Date" and check "Skip empty pages"
In Drupal 11 Filters work in lists etc., but not in calendars.
I haven't found a working filter in any calendar module yet. (Maybe someone can help me with this...) No changes are likely going to be made for Drupal 7, since that version of Drupal is no longer supported.
- π©πͺGermany 4kant
That wasn't my intention either.
I just wanted to show how the limitation could be implemented in Drupal 7.
I'm looking for help with Drupal 11. @anybody How would we modify the form elements to allow relative dates?
$form['date_range']['max_date'] = [ '#type' => 'date', '#title' => 'Enter Max date', '#format' => 'm/d/Y', '#description' => t('i.e. "09/06/2016" or "+1 year"'), '#default_value' => $this->options['date_range']['max_date'], '#attributes' => [ 'min' => \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime(), 'custom', 'Y-m-d'), ], ]; $form['date_range']['min_date'] = [ '#type' => 'date', '#title' => 'Enter Min date', '#format' => 'd/m/Y', '#description' => t('i.e. "09/06/2016" or "-1 year"'), '#default_value' => $this->options['date_range']['min_date'], '#attributes' => [ 'max' => \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime(), 'custom', 'Y-m-d'), ], ];
- Status changed to Needs review
17 days ago 4:25pm 14 May 2025 - First commit to issue fork.
- Merge request !61Issue #3096023: Merge latest 8.x-1.x and fix conflicts. β (Open) created by danmer
Is it possible to use service injection and avoid the \Drupal calls in the class?
- πΊπ¦Ukraine danmer
@solideogloria sure, I want to fix all PHP Sniffer issues, I'll fix the \Drupal calls as well, thanks
solideogloria β changed the visibility of the branch 3096023-add-option-to to hidden.
Would it be possible to allow strings to be entered for min/max date, and then call
strtotime()
in the lines something like this?$max_date = new \DateTime(strtotime($this->options['date_range']['max_date']));
That way, users could set the min/max to relative values like
-2 years