Problem/Motivation

Require on Publish (ROP) adds the .form-required-on-publish UI marker when a field is required only at publish-time.

Two gaps currently exist:

  • Some composite widgets (e.g. contrib phone_number ) build their label as a nested child render element (commonly $widget[0]['label'] ) which bypasses the normal form_element label pipeline; as a result, the ROP marker is not present on initial page load.
  • Name fields require special handling so only minimum components (and only when “Show component required marker” is enabled) receive the ROP marker on-load. Additionally, Name may render an alternate label via a themed description label render array which must also be marked.

This issue consolidates fixes for both:

Important: full correctness for Name component label behavior depends on Name exposing the required marker/states support for component labels; therefore this ROP work is dependent on Name's #3552451: Required state incorrectly marks non-minimum components as required.

Steps to reproduce

  1. Enable Require on Publish.
  2. Ensure Name module is installed and a Name field exists with minimum components configured.
  3. Ensure contrib phone_number is installed and a phone_number field exists.
  4. Mark the phone field as “Required on Publish” via the field configuration UI.
  5. Mark the Name field as “Required on Publish” via the field configuration UI and configure minimum components; toggle Name’s “Show component required marker” on/off to verify behavior.
  6. Open an entity edit form where these fields appear.
  7. Observe current behavior:
    • Composite widget labels may not show the blue marker on initial page load.
    • Name minimum component sub-field labels may not show the blue marker on initial page load (and the alternate label placement may not reflect ROP state).

Proposed resolution

  • Consolidate both on-load UI marker fixes into a single, refactored implementation in.
  • Apply on-load markers via #after_build where necessary, because some widgets do not pass through the standard preprocess label pipeline:
    • Composite widget labels: detect explicit label child render elements and add .form-required-on-publish on initial render when the field is not gated by #states['require_on_publish'] .
    • Name fields: when not gated, respect Name’s “Show component required marker” setting; mark only minimum components and ensure both the standard label and the alternate label placement (implemented as a themed label render array in #description) receive form-required-on-publish.
  • Continue to rely on states.js only for fields that are gated via Form API states ( #states['require_on_publish'] ).
  • Add/adjust test coverage under tests/ to cover:
    • Composite widget label on-load marking
    • Name minimum component on-load marking (as far as possible given Name behavior)
    • Non-regression for existing ROP behavior

Remaining tasks

User interface changes

  • Fields marked “Required on Publish” will consistently show the blue required marker (.form-required-on-publish) on initial page load for:
    • Composite widgets that render their label as a nested child element (e.g. contrib phone_number)
    • Name minimum component sub-fields (only minimum components, and only when Name is configured to show component required markers)
  • No change to behavior for fields gated by #states['require_on_publish']; those remain controlled by JS toggling.

API changes

None.

Data model changes

None.

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

jcandan created an issue. See original summary.

jcandan’s picture

Title: Fix blue required marker on load » Fix missing required marker on composite fields
Issue summary: View changes
jcandan’s picture

jcandan’s picture

Assigned: jcandan » Unassigned
Status: Active » Needs review
jcandan’s picture

Status: Needs review » Needs work
jcandan’s picture

Status: Needs work » Needs review
StatusFileSize
new43.46 KB
jcandan’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • jcandan committed 72260486 on 2.1.x
    fix: #3567063 Fix missing required marker on composite fields