When you edit an existing domain record and change its machine name, the validation fails saying that the hostname already exists.

Steps to reproduce:

- Create a domain record
- Try to edit the domain record and change its machine name
- You are unable to save the domain record

A workaround is editing the domain record changing its hostname temporarily to something else at the same time you change the machine name then editing again to change back the hostname to its original value.

CommentFileSizeAuthor
#4 2869197-domain-machine_name.patch2.29 KBagentrickard
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

recidive created an issue. See original summary.

agentrickard’s picture

A statement of the exact error message would be helpful, otherwise, this is a great report.

agentrickard’s picture

Here is the problem code:

    // Validate if the same hostname exists.
    // Do not use domain loader because it may change hostname.
    $existing = $this->storage->loadByProperties(['hostname' => $hostname]);
    $existing = reset($existing);
    if ($existing && $existing->id() != $entity->id()) {
      $form_state->setErrorByName('hostname', $this->t('The hostname is already registered.'));
    }

I think we can get around this by checking the domain_id() value, which is not editable.

    if ($existing && $existing->getDomainId() != $entity->getDomainId()) {
      $form_state->setErrorByName('hostname', $this->t('The hostname is already registered.'));
    }

I'll roll a patch in a minute.

agentrickard’s picture

Status: Active » Needs review
FileSize
2.29 KB

Here's a patch.

We were also checking this logic in Domain::preSave(), which was a precaution for auto-generated domains, but I think it is not needed.

agentrickard’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

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