Problem/Motivation

When a rate widget has "Use a vote deadline" enabled, RateHooks::entityView() ends with:

$this->entityDisplayRepository->getFormDisplay($entity_type, $entity_bundle)->setComponent($field_name)->save();

This runs on every render of an entity with the widget, not only when field_rate_vote_deadline is created. Since #3314312
the call passes no options. With no weight, EntityDisplayBase::setComponent() sets the weight to the highest weight in the display + 1. So on every uncached view:

  • the deadline field moves to the bottom of the form display, and if it is already last, its weight goes up by one each time
  • any widget settings for the field are reset to the defaults
  • the form display config entity is saved during a page request

On sites that manage configuration in code, this shows up as config drift in core.entity_form_display.* after normal page views, and the next config import reverts it.

Steps to reproduce

  1. Create a rate widget for a node bundle with "Use a vote deadline" enabled.
  2. View a node of that bundle once, so the field is created.
  3. Export configuration.
  4. Clear caches and view the node again.
  5. drush config:status lists core.entity_form_display.node.BUNDLE.default as Different; the field_rate_vote_deadline weight has changed.

Proposed resolution

Add the field to the form display only when the field config is created, inside the existing if (empty(FieldConfig::loadByName(...))) block. Existing sites keep whatever form display
settings they have. Patch attached.

Remaining tasks

  • Review the patch.
  • Add test coverage.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

ugolek created an issue. See original summary.

ugolek’s picture

Patch moves the form display setComponent()->save() into the field creation block, so it runs once instead of on every view.

ugolek’s picture

Status: Active » Needs review