Problem/Motivation

Using the 4.3.0 release, an issue not present in 4.2.8 surfaces: if the Smart Date field has been configured to populate a default date and the field widget has been set to "Always include an empty widget (Drupal default)," the empty widget will get populated with the default date.

This change was introduced in #3607075: Additional values should use the field defaults. While the rationale for that change makes sense for when a user explicitly clicks "Add another item," it has a significant negative impact where an empty widget is provided by default, in that it will populate an additional date instance that content editors probably don't expect.

Steps to reproduce

1. Create a node type with a single "Date and Time" field using the "Smart date range" field type. Set the "Allowed number of values" to "unlimited" and set the "Default date" to "Current date," leaving all other field type settings as-is.
2. Open the field widget configuration ("Manage form display") and check "Always include an empty widget (Drupal default). Otherwise the user must explicitly add a new widget if needed." and save the widget settings.
3. Use the "Node add" form to stage a node of this type.
4. Problem: Observe that the widget displays two date instances, and both are populated with the current date, where previously the second was left empty (as implied by the "Always include an empty widget" setting).

Possible resolutions

1. Option 1 (Recommended): Scope the auto-population behavior added in #3607075: Additional values should use the field defaults to only occur on explicit click by the user of "Add another item." This has the best chance of not disrupting existing sites that are using the "Always include an empty widget" option, while still honoring the intention of the new feature.
2. Option 2: Make a policy that the "Always include an empty widget" should in fact populate the default date, in which case the labeling should be updated to something like "Always include two date instances"??
3. Option 3: Revert the change introduced in #3607075: Additional values should use the field defaults, due to its negative interaction with with "Always include an empty widget" setting.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork smart_date-3612075

Command icon 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

mark_fullmer created an issue. See original summary.

sriram s made their first commit to this issue’s fork.

sriram_s’s picture

Status: Active » Needs review

Thanks for the clear options, mark_fullmer. Went with Option 1. Both issues can be satisfied at once. items_count distinguishes the trailing row from a requested one, so the default only applies where the user asked for it. Confirmed #3607075's case still works: show_extra off + "Add another item" still populates.

mandclu, heads up this changes a test from #3607075. testNewItemSlotReceivesComputedDefaultForSmartDateType asserted the show_extra slot must get computed timestamps, which is what's reported here, so it now covers a requested slot instead. Added one for the trailing row staying empty.

phpstan is red but pre-existing on 4.3.x, same 5 DI warnings with and without the patch, none in files this touches.