Problem/Motivation
The base widget SmartDateWidgetBase establishes a min and max year for the date picker functionality. Currently there is no way to configure this through the UI.
Proposed resolution
- Add configuration to field widget to allow adjusting the min and max default attributes.
Workaround
Process the form element to override the defaults:
$element["field_myfield"]["widget"][0]["time_wrapper"]["value"]["#date_year_range"]
$element["field_myfield"]["widget"][0]["time_wrapper"]["end_value"]["#date_year_range"]
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | smart_date-3300768-14.patch | 967 bytes | jrockowitz |
Issue fork smart_date-3300768
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
joewhitsittThe min and max attributes are only set when the field has a value (e.g. default value)
docroot/core/lib/Drupal/Core/Datetime/Element/Datetime.php - processDatetime()
Comment #3
joewhitsittComment #4
joewhitsittAdding reference to core issue for similar functionality
Comment #5
mandclu commentedBased on my own (admittedly limited) investigation, it seems as though we should be able to set #min and #max values, in addition to #date_year_range. Personally I'd prefer the two former (provided they actually work) as it sounds like they could provide more granular control, for example with a DrupalCamp restricting sessions to be scheduled during the days the camp actually runs.
Comment #7
mandclu commentedI ended up implementing this not as much in the widget configuration but in the field settings. Will open a child issues around adding a validation constraint so these can also be enforced when creating values programmatically, and also to make sure that these are respected for recurring values.
Will likely roll this into a beta release.
Comment #8
joewhitsittThanks for this @mandclu. We will revisit our workaround when this is released.
Comment #9
mandclu commentedThis has been included in the most recent release.
Comment #11
joewhitsitt@mandclu
I finally got a chance to look at this along with the schema commit and I am getting undefined array key min and max related to the "next hour" default functionality here if I leave the min and max blank like the help text says (not required).
https://git.drupalcode.org/project/smart_date/-/commit/4aa93f7#39ea69cdc...
When the min and max are set, instead of the next hour (today plus one hour), it defaults to the max limit (set as 2037-12-31) plus one hour. I think that is because of a typo
Should be:
Comment #12
mandclu commentedAh good catch. Did you test if it works as expected with that change?
Comment #13
joewhitsittI did in that very specific situation. Haven't had a moment to submit an MR and wasn't sure if it should be a separate issue
Comment #14
jrockowitz commentedHere is a quick fix
Comment #15
joewhitsittThanks @jrockowitz
I created an MR to cover both the if not empty check and the only if greater than max check.
Comment #17
mandclu commentedThanks for everyone's work on this. The latest changes are merged into the 3.6.x and 3.7.x branches.