Overview
#3545859: Add a `host-entity-url` prop source for linking to the host entity introduced HostEntityUrlPropSource but it supports only the host entity. However, there are many valid use cases to link to entities that are other than the host entity; for example, if you are rendering tags, you may want to link to the taxonomy term canonical page to list more content with the same tag or you may want to link to the users profile.
The end user goal makes sense, the proposed technical implementation does not, and led this issue into some chaos due to how #3545859: Add a `host-entity-url` prop source for linking to the host entity landed. Fortunately, we quickly recovered from the chaos by having conversations between @Wim Leers, @lauriii, @phenaproxima and @effulgentsia. 🤝
Proposed resolution
Expand this feature to ensure all entities that may be accessed in content templates, not just the host entity, can be used in link props.
See #3545859-48: Add a `host-entity-url` prop source for linking to the host entity.
User interface changes
Tested while editing the ContentTemplate for article Nodes, using the type: string, format: uri-reference prop in the "all props" test SDC:
- Before

- After

| Comment | File | Size | Author |
|---|---|---|---|
| #34 | Screenshot 2025-11-18 at 1.08.58 PM.png | 580.58 KB | mayur-sose |
| #26 | Screenshot 2025-11-05 at 10.32.36 AM.png | 74.07 KB | wim leers |
| #25 | Screenshot 2025-11-05 at 10.06.05.png | 89.23 KB | lauriii |
| #19 | Screenshot 2025-11-04 at 17.57.35.png | 46.87 KB | lauriii |
| #19 | Screenshot 2025-11-04 at 17.57.27.png | 30.88 KB | lauriii |
Issue fork canvas-3555413
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 #2
phenaproximaWell, wait a sec. Wouldn't that just be a normal entity reference field-powered link? Surely that would be done with a dynamic prop source (perhaps with an adapter on top of it), since those can target any property of any field at any level of a reference chain.
Don't get me wrong, we do need the ability to link to referenced entities for sure, but I don't think that's the intention of HostEntityUrlPropSource.
Comment #3
wim leersDid that for you this time.
ContentTemplateUI.HostEntityUrlPropSourcetoEntityUrlPropSource, because it would no longer be limited to the host entity.The number of ambiguities in
is staggering:
- suggest URL to the author (User) of a Node (1 reference), but NOT URL to the user picture of the author (User) of the Node (2 references)
- suggest URL to the "primary topic" (Term) of a Node (1 reference), but NOT URL to the "resident expert" (User) of a "primary topic" (Term) of a Node (2 references)
Or did you really want the entity URL to be available at every one of those levels? (Which your phrasing seems to imply.)
Files", which also means linking to it becomes harder. Or did you want for a media entity both the "media item canonical URL" and "media item image file canonical URL" to be surfaced?EDIT: or, I guess you would've expected this to return an array of links (
type: array, items: {type: string, format: uri|uri-reference}? Even though that's still not yet supported for the much simpler "static value" case: #3546869: Editing support for `type: array`: support multiple-cardinality Field Widgets (`StaticPropSource`s).)… I'm pretty sure there's more things still, but those are the immediate ones that come to mind.
🙏🙏🙏🙏 Please create a mock-up of what you expect, such as the one in #3547598-23: Refine API response with DynamicPropSource suggestions to provide better UX. Please think through all the above aspects and indicate what is in scope vs what is not.
Comment #4
wim leersd.o's "cross-posting causes unpublishing" bug strikes again 🫣
Comment #5
wim leers@phenaproxima in #2:
Conceptually, @lauriii is asking to make for every entity reference encountered (not sure if at the top level or also deeper, see my prior comment), we also offer a
HostEntityUrlPropSourcefor the referenced entity.\Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::propertyDefinitions()does not have a property that generates a URL, so relying on the existing reference fields is insufficient.🤔 But … perhaps that is reasonable to do? #3545859: Add a `host-entity-url` prop source for linking to the host entity did what it did because we didn't want to add a computed field to all of the entities. But for an entity reference to provide a canonical URL to the referenced empty … that seems kinda reasonable? Probably only the
canonicaland relative (so:type: string, format: uri-reference) one, and that'd be sufficient for 99% of cases?(That would also be compatible with #3551455: HostEntityUrlPropSource should be able to support absolute or relative URLs, URL options, because you'd be unlikely to ever want to link to "the edit form of the referenced user/term" — that'd be more likely to only occur for the host entity itself.)
Comment #6
wim leersFYI: tagged because of
i.e. we shouldn't be doing such a significant change after 1.0. That'd be too disruptive.
Comment #7
lauriiiI would expect this to inherit our existing limitations for level of depth, i.e. the link should be available for all of the entity references that are accessible there. So if user can map an image field to a user picture, they should be able to map a link field to the user pictures URL. Same is true for the resident expert for the primary topic.
For images this is already working as expected. It doesn't look like mapping to media references is working yet but I would expect that it should be possible to link to the media item image file canonical URL.
Could we just call it URL and Slug? They should not appear as siblings; they should appear under a child menu. For example, Image => URL or Authored by => URL.
Comment #8
lauriiiComment #9
wim leersThis will require a significant refactor, then:
HostEntityUrlPropSource→EntityUrlPropSourceand for anything except the host entity, we'd require an expression (that explains how to traverse the Typed Data tree), just like forDynamicPropSourceHostEntityUrlPropSourcetoday is stupid simple, because it doesn't need to traverse Typed Data. That will need to be refactored to share a subset of that infrastructure withDynamicPropSource's matching logic.You casually say "inherit our existing limitations of level of depth", but this is quite complex to achieve, because these URLs that are offered to users are NOT part of Typed Data! If on #3545859: Add a `host-entity-url` prop source for linking to the host entity these product requirements had been conveyed, I would never even have suggested this new prop source type! 😬 Because if we expect such close integration, just adding new computed fields would be a LOT simpler 😅 In fact, it might still be preferable to backtrack/revert our prior decision then…
Do you expect this all to be done before 1.0, or after?
I think by "slug" you refer to path alias and by "URL" you refer to
/node/<nid>? If so, please chime in on #3551455: HostEntityUrlPropSource should be able to support absolute or relative URLs, URL options for that.But that's not what I was saying/asking there. I was asking specifically about the collapsing/simplifying you asked us to implement for File entities into the containing Media entity. Which starts to fall apart when there's then 2 URLs that are supposed to appear: how do you expect those to be labeled and ordered relative to other suggestions?
Comment #10
wim leersSo, to make #9 very concrete, I am proposing to remove
HostEntityUrlPropSourceand add computed fields to all entities instead:— me, at #3545859-41: Add a `host-entity-url` prop source for linking to the host entity
Comment #11
wim leersPostponed #3551455: HostEntityUrlPropSource should be able to support absolute or relative URLs, URL options and #3555068: Linking a `HostEntityUrlPropSource` to populate a `type: string, format: uri|uri-reference` in a `ContentTemplate` has no effect on #10, to avoid even more potentially wasted effort.
Meeting with @lauriii on Monday. Pinged @effulgentsia and @phenaproxima, who led the charge on landing #3545859: Add a `host-entity-url` prop source for linking to the host entity, and so should definitely chime in.
Comment #12
penyaskitoAfter reading this #10 makes sense to me. And if this needs to be solved for Drupal CMS, I wonder if providing that computed field should be the responsibility of canvas or a different specific contrib module.
Comment #13
wim leersMarked #3545859 unfixed in #3545859-45: Add a `host-entity-url` prop source for linking to the host entity.
Comment #15
wim leersDiscussed yesterday with @lauriii, and then with @effulgentsia.
Conclusion: a hybrid between what we have in HEAD (we'd keep
HostEntityUrlPropSource), but add a new computed field property to entity reference fields.Details:
— #3545859-48: Add a `host-entity-url` prop source for linking to the host entity
AFAICT this addresses all concerns by both @lauriii from a product POV and the technical/feasibility concerns I raised here 😊
MR up with a first commit that starts building this. The first commit gets us to the point where indeed all entity reference fields are suggested, including nonsensical ones:
Comment #16
wim leersIt works.
Tested while editing the
ContentTemplatefor articleNodes, using thetype: string, format: uri-referenceprop in the "all props" test SDC:Comment #17
wim leersComment #18
phenaproximaI have almost nothing left to complain about; just moving a couple of comments around, and adding a little more high-level explanation to one thing. But otherwise, I say SHIP THIS CHUNGUS!
Comment #19
lauriiiTesting this and this is definitely a really nice improvement already! A bit of feedback / questions:
Images seem to introduce some interesting. It looks like we could map the image to "image" but there's also URI and root-relative URL. What's the difference between these different mappings?
This might be something for a follow-up but I don't think we should be exposing the author of the file entity in the UI at all.
Comment #20
wim leerssrc_with_alternate_widthscomputed property that Canvas added.You can only see all 3 if you have an SDC/code component prop with a very open-ended prop, because the second one returns a
public://URI. but, arguably, it does not make sense to expose "root-relative file URL" for an image field, either, becausesrc_with_alternate_widthsis likely preferable. Except … if you want to link to the original image, because then the query string is just noise.⚠️ This is confusing because of the simplification you requested previously: the omitting of intermediary levels (which I referred to in #3.2). Because if it'd said "Image → File → URI → Root-relative file URL", it'd have been much clearer that "URI" was a field on the File entity. This is tricky to get just right from a UX/Product POV 😬
Proposal: special-case the "URI" field on the File entity type to always show the specific description of the field property, even for the main property. And possibly also change the label of that base field to "File URI". Which would then result in:
What do you think?
urlproperty. To achieve , we'd need to add a computed base field to all entity types, which is exactly the thing that is so problematic: likely clashes with contrib/custom modules, as @effulgentsia and I explained at #3545859-48: Add a `host-entity-url` prop source for linking to the host entity.Comment #21
phenaproximaThis is great, and useful, and clear as a bell. I'm shipping it with my newfound commit powers! Mwahahahahahaha!!!
Comment #22
phenaproximaOkay, looks like I can't merge this without it being approved by the correct code owners. Boo!
Comment #23
effulgentsia commentedRTBC+1. I approved for the code groups that I'm a code owner of but that still leaves a couple groups that need approval.
Comment #24
larowlanLeft two comments that I think can likely be followups given this is RTBC and critical
Comment #25
lauriii#20.1I think with the improved labels it would have made sense to me what was being offered there. FWIW, I was testing this with code components so maybe the prop type in code components should be setting stronger restrictions for the stream wrapper URL to not be offered?
#20.2: Will add it there 👍
#20.3: I see. 👍 I don't think the current solution of displaying the URL outside of the entity is perfect but I'm not convinced it's bad enough to warrant significant rework. It's a bit strange when you see both levels there but people will probably just figure it out.
Comment #26
wim leers@phenaproxima & @effulgentsia: thanks both!
@larowlan in #24:
Addressed both 😊 Keeping technical debt/issue queue sprawl under control by spending 15 mins addressing those here is worth it IMHO 👍
@lauriii in #25:
This is what that UI currently looks like, annotated to convey what the coarse prop shapes are that you're allowed to pick:
👉 Detailed proposal in new issue: #3556144: Code components "link" props can only be coarse, resulting in irrelevant shape matches when building `ContentTemplate`s
Comment #27
wim leersThis is now finally fully ready.
Note that manually testing this in a
ContentTemplatewhen the referenced entity is inaccessible reveals that the resultingNULLvalue causes an SDC render crash.The reason:
\Drupal\Core\Theme\Component\ComponentValidator::validateProps()requires optional SDC props to be ABSENT or have a valid value. So what is NOT allowed is a value sometimes resolving to a a string (e.g. node 5's referenced entity is accessible ⇒ result = URL) and sometimes not (e.g. node 6's referenced entity being inaccessible ⇒ result = NULL).We've already got #3541361: Find optional field instance matches for `type: object` props (images + videos), including for optional fields on bundleless entity types (e.g. `User`'s `user_picture`) for that, and that already has test infrastructure for it. So keeping that out of the scope here — this MR is already plenty complex as-is 😅
Comment #28
phenaproximaGave this another look. The comments make fairly clear what's going on here, and the
MaybeUrlvalue object makes sense as something we can adapt in the future if we run into a similar need for a "this could a useful value, or it could NULL because of an access problem" case. I appreciate the added clarity (in the class doc comment) about howEvaluatorwill handle a required value that fails to produce a value. These are really complex problems, and I hope that core will be able to improve the status quo over time, but for now......ship it.
Comment #30
wim leersThanks! Now see y'all in #3541361: Find optional field instance matches for `type: object` props (images + videos), including for optional fields on bundleless entity types (e.g. `User`'s `user_picture`) per #27, in #3551339: Suggest only relevant DynamicPropSources for omitting irrelevant suggestions, and in #3551455: HostEntityUrlPropSource should be able to support absolute or relative URLs, URL options to make
HostEntityUrlPropSourcefeature-complete and update-path-free.Comment #32
penyaskito#27 would also be alleviated if #3531905: Validation error on optional properties. lands
Comment #33
wim leers@penyaskito: #3531905-23: Validation error on optional properties.. 🏓
Comment #34
mayur-sose commentedVerified below scenarios on 1.x :
Please check TC05, failed test case.
Output updates accordingly.
Comment #35
wim leersTC05 (selecting ) is explicitly not in scope of this issue.
The fix for that landed in the past hour: #3555068: Linking a `HostEntityUrlPropSource` to populate a `type: string, format: uri|uri-reference` in a `ContentTemplate` has no effect.