Core deprecated the uri_callback entity type property in drupal:11.4.0; it is removed in drupal:13.0.0. Change record: https://www.drupal.org/node/3575062
The domain entity type still declares it, pointing at Domain::uri(), which returns Url::fromUri($domain->getPath(), ['absolute' => TRUE]), an absolute URL on the domain record's own hostname.
Since #3541558: Remove the remaining plugin annotations from the 4.x branch moved the entity type declaration to a PHP attribute, the deprecation is now triggered at plugin discovery time by the Drupal\Core\Entity\Attribute\ConfigEntityType constructor, so it shows up in every test run that installs the module. With the annotation it only fired when EntityType::getUriCallback() was actually called.
A link template cannot replace the property here: the canonical URL of a domain record is an absolute URL on another host, not a route on the current site.
Proposed resolution:
- Override
toUrl()inDrupal\domain\Entity\Domainso that thecanonicalrelation returns that absolute URL while every other relation falls through to the parent implementation, then remove theuri_callbackproperty. - Keep
Domain::uri()as the single place that builds the URL, or fold its body into the override. - Review the consumers that depend on the canonical relation, in particular the core entity reference label formatter when a
domain_accessordomain_sourcereference is rendered as a link.
Testing: add a kernel test asserting that $domain->toUrl('canonical')->toString() still returns the absolute domain URL, and confirm the deprecation is gone from the test output.
This is 4.x only: 3.x supports Drupal 10.2 and 11, where the property is still available.
Issue fork domain-3613276
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
Comment #3
mably commentedMR !413 opened against 4.x.
The deprecation fired from two places, both now gone: the
ConfigEntityTypeattribute constructor at discovery time, andEntityType::getUriCallback()on eachtoUrl('canonical')call.Domain::toUrl()now handles thecanonicalrelation itself and delegates every other relation to the parent.Domain::uri()stays as the single source of URL construction. The override replicates the callback path exactly, including the entity data passed through as options and the configuration entity convention of not setting an explicit language.On consumers: the entity type has no
canonicallink template, sotoUrl()with no argument still resolves to the edit form. That is the relation the entity reference label formatter uses, so domain reference fields keep linking to the edit form, as before.New kernel test
DomainUrlTestcovers the canonical URL, the path prefix, option merging,toLink(), the other link relations, an ID-less record, and the absence of the property on the entity type.Verified against Drupal 11.4.4: before the change the new test class reports the deprecation from both call sites in every test; after it, the whole
domainkernel suite (87 tests) and the three entity reference functional tests pass with nouri_callbackdeprecation left.One thing found while writing the test, unrelated and left alone: the
collectionlink template resolves to the route nameentity.domain.collection, which the module does not declare (the route isdomain.admin), so$domain->toUrl('collection')throws aRouteNotFoundException. Filed as #3613844: The collection link template of the domain entity type points to a route that does not exist.Comment #5
mably commented