Default domain values not set and overridden by current domain

Created on 6 June 2023, over 1 year ago
Updated 9 August 2024, 5 months ago

Problem/Motivation

When creating a new entity, the default domain value(s) for the bundle are not being set.

The first issue is that the default value of the field is overridden by the active domain. This change was introduced in this issue β†’ with this change in the hook_field_widget_form_alter..

Domain Access does have logic to set the default value to the current domain, but only does so if the field is required.

The second issue is that the default domain values are not being set properly because the array returned by the third party setting is keyed with strings instead of numerically. In Drupal Core's FieldInputValueNormalizerTrait::normalizeValue method, if the keys are not numeric, it will re-key all values under the 0 key. That results in only 1 of the selected default domains being set.

Steps to reproduce

  1. Enable domain entity access for an entity
  2. Set the behavior User ("User choose affiliate, with the default value (form widget on the entity creation form")
  3. Check multiple default domain value(s) for the bundle
  4. When creating a new entity, only the current domain will be checked instead of the values configured.

Proposed resolution

To solve the first issue, I propose that checks are added to only populate the value of the field if the field is required and no default value has already been set.

The second issue can be solved by using numerical array keys when setting the default value.

A MR has been created.

πŸ› Bug report
Status

Needs review

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mtalt Maryland

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024