Problem

When I want to create an alias, I cannot save it – Redirect field gives error: The value you selected is not a valid choice.

Steps to reproduce

  1. Fresh Install
  2. Create domain
  3. Try to add alias
  4. Cannot save
CommentFileSizeAuthor
Screenshot 2026-02-25 at 19.24.12.png38.13 KBkergand

Issue fork domain-3575783

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

kergand created an issue. See original summary.

mably’s picture

Thanks @kergand for creating an issue. Investigating.

mably’s picture

Status: Active » Needs review

Root cause

DomainAliasForm::validateForm() was validating $this->entity->toArray() directly, but never called $this->buildEntity() first. In Drupal's EntityForm lifecycle, validateForm() runs before submitForm(), so the entity still has its default property values — not the submitted form values.

For a new alias, the $redirect property on DomainAlias has no default value, so it is NULL. The config schema defines a Choice constraint allowing only [0, 301, 302], and NULL does not match — hence the validation error "The value you selected is not a valid choice."

A secondary issue: HTML <select> elements always submit string values ("0", "301", "302"), but the schema Choice constraint compares against integers. Even after building the entity from form values, the string-to-integer mismatch would still cause a failure without an explicit cast.

Fix

Two changes in DomainAliasForm::validateForm():

  1. Cast the redirect form value to (int) before building the entity, so the integer type matches the schema's Choice constraint.
  2. Call $this->buildEntity($form, $form_state) to populate the entity from submitted form values before running validation — instead of validating the stale $this->entity.

Test coverage

Added DomainAliasFormTest — a functional test that submits the alias creation form via the UI for each valid redirect value (0, 301, 302), then edits an existing alias to change its redirect. Verified that the test fails without the fix and passes with it.

mably’s picture

@kergand can you confirm that this issue's MR fixes the problem? Thanks.

kergand’s picture

Yes, it seems now is ok

  • mably committed f9255d3a on 3.x
    fix: #3575783 Domain alias cannot save
    
    By: kergand
    By: mably
    
mably’s picture

Status: Needs review » Fixed

Thanks. Merged.

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.

  • mably committed 321474ac on 3.x
    fix: #3575783 Clean up DomainAliasForm and DomainForm validateForm()...

Status: Fixed » Closed (fixed)

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