Needs work
Project:
Drupal core
Version:
main
Component:
datetime.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
15 Dec 2016 at 11:31 UTC
Updated:
20 Apr 2026 at 08:48 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #3
larowlangiddyup
Comment #4
larowlanThis works for me
Comment #5
jibranThis is an experimental module so no need for the upgrade path and upgrade path tests.
Comment #6
jhedstromA few questions/comments here.
Why is this only specific to the daterange field? Both normal datetime and date range fields support select list entry. Also, this is currently applied as a setting regardless of the form widget selected. It is only applicable to select list entry I think (unless it is meant to validate/constrain dates between those years, in which case it needs work since that bit isn't working...).
Comment #7
mpdonadioAlso, we already have a Datelist form element, which that widget is using. Can't we just expose the setting and then stuff it into #date_year_range key in DateRangeDatelistWidget::formElement() and DateTimeDatelistWidget::formElement().
Since PluginSettingsBase::getSetting() merges in defaults, I don't think either would need an upgrade path and upgrade path tests, just a cache clear.
Comment #8
larowlanThat's what the patch does, the YearRange form element is just for the settings form, borrowed from the approach in date_api in D7.
I agree, this can go up one layer further to the single date field, but that'd be in the non-experimental module.
Comment #9
jibran> I agree, this can go up one layer further to the single date field, but that'd be in the non-experimental module.
Let's do that. I believe we can add new features to any module in a minor release.
Comment #10
mpdonadioI just re-read this. Haven't played with it applied, but I like the better UX of the form element approach rather than a simple text field.
And yeah, this can go into the datetime version, too. As long as the datetime version doesn't depend on the daterange one, they this is a valid new feature for 8.4.x: it adds a new admin feature to an existing form in a non-disruptive way. A select with 150 things in it is a UX WTF anyway.
static
I don't think the setting should be on the base class, just the list widget.
Extra indent.
We can just use the ->save() w/o an intermediate local variable.
Can use [].
Looks like there is no coverage of the new form element on the manage display or did I miss something?
Comment #11
jibranComment #12
Munavijayalakshmi commentedComment #13
Munavijayalakshmi commentedRerolled the patch.
Comment #14
jofitzFixed minor coding standards issues.
Removed Needs Reroll tag.
Comment #15
mpdonadioDoesn't look like #10 has been addressed.
Comment #16
jofitzSorry, my mistake. I didn't read properly and assumed they had all been address in #13.
Comment #17
jofitzComment #19
jofitzAdd defaultSettings() to DateRangeDefaultWidget too.
Comment #20
mpdonadioDid some manual testing.
Currently doesn't work on datetime fields. Let's make it work there, too.
Like the way this works on daterange. Big UX win.
Comment #22
jofitzPatch in #19 no longer applies cleanly. Re-rolled.
Comment #23
jofitzAdded to datetime fields in the same way it is on daterange fields.
Comment #25
mpdonadioI think we need to move this to DateTimeWidgetBase.
Need to look at this applied, but this looks like it could be out of scope? But if we do the #1 bit, then this is probably needed.
This def needs to move to DateTimeWidgetBase() so it is available in all of the Datetime widgets.
This can't be in datetime_range. At a min, it needs to be in datetime, but possibly in with the core Elements since there could be value outside these modules.
?
See above bit about moving to the base class.
Need to add coverage for the datetime widgets and mirror the test in datetime module for these settings.
Comment #26
jofitzAlso fixed test failure and coding standards error.
Comment #28
jofitzCorrected error in new test.
Removed unused use statement.
Comment #29
jhedstromShould we add a kernel or unit test specific to this new render element? I was trying to find a specific one for the existing data render element, but could not find one, however many render elements have dedicated unit tests. These public methods seem pretty easy to unit test.
Let's add at least one test that deals with relative dates to ensure those are working (eg, -3:+3).
Comment #30
mpdonadioAgree with needing a little more test coverage.
#2 should test 1978:2017, -3:2017, 1978:+3, -3:+3, ie all of the possibilities.
Comment #31
anas_maw commentedNot working if you don't give the field default value.
Comment #32
jofitzComment #33
anas_maw commentedHello is it possible to make this work if we use 'now' date for example?
Also try to enter start day +1 and the end date +10 for example, this is not working.
Comment #34
jofitz@Anas_maw Rather than 'now' you can use '+0' (or perhaps open a follow-up issue).
What is not working with '+1:+10'?
Comment #36
jofitzComment #37
josue2591 commentedTested in 8.6.x. Works.
Comment #38
mpdonadioWe need to add a check so that the start year <= the end year, and test coverage for that.
Comment #39
jibranNow that
datetimeanddatetime_rangeare not experimental anymore we need an upgrade path and upgrade path test as well.Comment #40
mpdonadioSince these are just widget settings with default values, don’t we just need an empty post update to trigger a rebuild?
Comment #41
jibranAs we are adding a new key to the
datelistanddefaultformatters we need to update the config for the existing field formatters with the new key and default values.Comment #42
iyyappan.govindHi Team,
I love this post. I have same issue, I just used the form_alter to restrict the date range. So my date range is 1990 to current year. It works fine but I need the descending date sort order, means 2018, 2017, ...1990. Is this possible via form alter? It would be great if we implement the sort order in UI if it is not in date form api.
Thank you.
Comment #46
rob230 commentedWould love this feature as well. It's not very useful for example to have a date of birth field where you can choose 2050 as the year.
Comment #47
manuel.adanJust 8.8/8.9 re-roll with no additional changes.
Comment #49
mpp commentedThe patch in #47 has an issue with the namespace for t()
MachineNameTest.php also defines Drupal\Core\Render\Element\t, not t() so function_exists will return false (see https://www.php.net/manual/en/function.function-exists.php#117916) but will trigger this error:
Comment #50
raman.b commentedUpdating Functional tests & addressing #49
Comment #51
raman.b commentedComment #54
kim.pepperComment #58
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #59
damienmckennaRerolled, applies cleanly against 9.5.x and 10.1.x.
Comment #60
damienmckennaAm working on the fixes.
Comment #61
damienmckennaThis will hopefully fix the problems; I accidentally lost the t() function change in YearRange.php.
Comment #62
damienmckennaI don't understand why the t() change is required in the first place? But it's causing the test to fail.
Comment #64
damienmckennaComment #65
sethhill commentedRerolled the patch in #61 against 10.3.x
Comment #68
danielvezaConverted the patch from #65 to an MR. Lets see how the pipeline looks
Comment #69
danielvezaPassing pipeline, now with update path & tests
Comment #70
smustgrave commentedCan the IS be updated to use the standard template please.
Thanks
Comment #72
anybodyThis is not only to broad for certain cases, it's also to limited for others, e.g. if using Drupal for historical data.
See my comment in #2942828: Remove hard-coded #date_year_range making it impossible to enter dates < 1900, > 2050. Instead make them optional and configurable in the UI. I'm unsure if we should better proceed here and postpone the other issue or start from scratch over there. The issue summary here was focused on "datelist" (List!) where such a limit at least makes some sense, but currently the limit also applies to HTML5 datepicker, which is a bug. That's what the other issue is about.
However, we should get this finished.