Problem/Motivation

Two changes on core development branch broke 4.x this week, and both show up in the phpunit (next major) job.

1. The RouteProvider constructor. DomainSourceRouterProviderTest builds DomainSourceRouteProvider by hand and passed the table name router as the seventh argument. Drupal 11.4 inserted $fast_cache ahead of $table (#3503843: Remove automatic preloading of all "public" routes, cache routes in fast chained bin) and kept a BC branch that accepted a string there; #3614493: Remove BC from RouteProvider::__construct() removed that branch, so both cases now error with TypeError: Drupal\Core\Routing\RouteProvider::__construct(): Argument #7 ($fastCache) must be of type Drupal\Core\Cache\CacheBackendInterface, string given. Only the test is affected: domain_source.route_provider is declared with parent: router.route_provider, so core builds the arguments at runtime.

2. The shape of submitted options widget values. #2171395: OptionsWidgetBase should use WidgetInterface::massageFormValues() moved the transposition of options widget values out of validateElement() and into massageFormValues(), which core calls when it builds the entity. Values in $form_state therefore keep the widget own shape through validation and through submit handlers, where they used to arrive as [delta => [target_id => id]]. Two places read them there.

DomainElementManager::submitEntityForm() appends the disallowed domains as [target_id => id] onto whatever $form_state holds. Against the new order that produces a mixed array, so core wraps a whole array as a target_id and saving the form fatals with InvalidArgumentException: Value is not a valid entity, a 500 on the POST. That is DomainAdminElementTest, DomainReferencesTest, DomainAccessElementTest, DomainAccessDefaultValueTest and DomainAccessLanguageSaveTest, the last of which reports it as a count mismatch because the save never completed.

DomainSourceFormHooks::formValidate() compares the selected source domain with the domain access selections, handling exactly two value shapes. With both fields in widget shape neither matches, so a valid selection is rejected with "The source domain must be selected as a publishing option." In DomainSourceElementTest the node is then never created and the following request for its edit form returns 404.

Proposed resolution

Pass a mocked cache backend as the seventh constructor argument, the table name as the eighth and the language manager as the ninth. That is the signature Drupal 11.4 introduced and the only one the development branch accepts.

Add DomainElementManager::getSubmittedFieldValues(), which takes the widget off the form display in the form state and calls massageFormValues() on it, the method #2171395: OptionsWidgetBase should use WidgetInterface::massageFormValues() moved this logic into. Nothing about the widget shapes is repeated in domain, so the autocomplete widget is handled as correctly as the options ones, and a further change to the shape in core needs no change here. On Drupal 11.4 OptionsWidgetBase has no massageFormValues(), so WidgetBase returns the already transposed values unchanged; on the development branch the widget transposes them. Both handlers go through it, and the validate handler loses its two-shape branching and its @phpstan-ignore comment.

The validate handler also stops naming DomainAccessManagerInterface before it has checked that domain_access is installed. domain_source does not depend on domain_access, so resolving that class constant first is a fatal error wherever domain_access is absent, which DomainSourceEntityReferenceTest shows on both majors.

Remaining tasks

Review the merge request. This must not be backported to 3.x or 3.0.x, which support Drupal 10.2 and 11 and are not affected.

User interface changes

None.

API changes

DomainElementManagerInterface gains getSubmittedFieldValues().

Data model changes

None.

AI-Generated: Yes (Claude Code was used to help draft this issue summary and to write the code and tests on the merge request. I reviewed and ran the work myself before posting it.)

Issue fork domain-3616749

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

mably created an issue. See original summary.

mably’s picture

Title: DomainSourceRouterProviderTest fails on Drupal 12: RouteProvider::__construct() no longer accepts the table name as its seventh argument » Drupal 12 compatibility: the RouteProvider constructor arguments and the shape of submitted domain field values
Issue summary: View changes
mably’s picture

Issue summary: View changes

  • mably committed e643b569 on 4.x
    fix: #3616749 Drupal 12 compatibility: the RouteProvider constructor...
mably’s picture

Status: Active » 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.