Problem/Motivation
Currently, the Year Only doesn't provide useful default value options. The only settings are '- None -' and '0'.

Default values could provide an improved user experience, e.g in cases where there is a large range of years, or the current year is most-commonly used.
Proposed resolution
Implement YearOnlyFieldItemList to provide useful default options (e.g. current year, relative year, specific year).
Remaining tasks
Write the patch- Review
- Commit
User interface changes
Add a select for default value type. Provide dependent fields to collect relative date string (strtotime) and/or specific year value.
Data model changes
Add default_type, default_relative and default_specific to schema.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | Screenshot 2025-01-03 at 4.51.31 PM.png | 49.71 KB | pcate |
| #14 | yearonly-default-options-3172745-14.patch | 7.8 KB | justcaldwell |
| #13 | Screenshot 2024-07-01 at 6.06.43 AM.png | 330.16 KB | gab. |
| #8 | yearonly-default-options-3172745-8.patch | 7.73 KB | peacog |
| #2 | yearonly-default-options-3172745-2.patch | 7.69 KB | justcaldwell |
Issue fork yearonly-3172745
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
justcaldwellPatch attached. Adds options for:
For example:

Comment #3
pcate commentedPatch worked for me. Also, although this is marked as for 9.x, it applied fine with the latest 8.x release.
Comment #4
pcate commentedComment #5
joel_osc commented+1 RBTC works great, thank-you!
Comment #6
la558 commentedUpdate:
Please disregard.
The problem was that the patch was not being applied correctly.
Now, I'm able to see the 3 appropriate options.
Hello,
Could it be that something has changed.
After applying the patch, all what I see on the default options drop down list, are a list of years.
'Current year', 'Relative year', and 'Specific year' are no set as options.
Thanks!
Comment #7
justcaldwellComment #8
peacog commentedRe-rolled for 9.1
Comment #9
crutch commentedPatch didn't apply to 9.1 but did for dev and works as expected. Thank you
Comment #10
gaurav-mathur commentedComment #11
gaurav-mathur commentedPatch #8 applied successfully on Drupal 9.4.3 and PHP 8.1.6.
The patch work properly for me.
Thanks.
Comment #12
adaragao commentedDoesn't work on Drupal 10.3
Unfortunately I'm not a developer, can someone fix it, please?
Comment #13
gab. commentedThis is still not fixed on 9.1

Patch #8 did not work for me, couldn't be applied on 9.1
Comment #14
justcaldwellHere's a patch re-rolled for 9.1.1 and/or 9.x-dev. Please give it a try.
Comment #15
adaragao commentedPatch 14 also works on Drupal 10.3.1. Thank you !
Comment #16
pcate commentedPatch #14 worked for me with the latest 9.1.2 version of the module.
Comment #19
vitaliyb98 commentedMoved changes from patch #14 into MR
Comment #20
vitaliyb98 commentedPHPCS and PHPSTAN pipelines failed, moved the issue to the Needs work
Comment #21
vitaliyb98 commentedFixed pipelines
Comment #22
justcaldwellComment #23
justcaldwellCleaned a field description and some error messages, and adjusted validation to ensure any default value is within the min/max year range regardless of type.
I did quite a bit of manual testing and I feel like this is ready. I'll leave it on Needs review for a while in case someone else can test/review.
Comment #24
vitaliyb98 commentedHi, I will try to review it and make some manual testing this week.
Comment #25
vitaliyb98 commentedHi @justcaldwell, I tested it with Drupal 10, and it works fine, but I found a problem with #states in Drupal 11. States for the default year selector don't work. (Drupal 11.2.0, admin theme: Claro)
Here the reason:
In Drupal 10, select the element: (id="edit-default-value-input-default-type")
In Drupal 11 ( id="edit-default-value-input-default-type--M7GELMJWr64"):
Thats why states not worked in Drupal 11:
I suggest we could change it to:
Comment #26
justcaldwellGood catch, Vitaliy — thanks.
Updated and confirmed the fix also works with Drupal 10. I'm calling this fixed, and will merge soon.