I have a Drupal link field configured to allow both internal and external links and have the title field enabled, but optional.
I want users to be able to reference internal entities without having to specify anything in separate title field, and have the Link field's title pulled from the entity label. However it appears that when the field's internal title
value is left null, Drupal ends up using the field's uri
value as the link title. This behavior seems odd to me.
My question is this: given an internal uri
value that looks like: entity:node/3500
how can I preprocess or alter the functionality of the Link field to load in the entity's title/label as the title
when it is left empty by the content editors.
I've searched for issues on drupal.org but didn't turn up much of anything useful. I found Get title from Route, which seems to recommend using the TitleResolver, but that depends on putting together a $request object, which seems extremely impractical.
Suggestions?
getTranslationFromContext()
, get the title and add the cache metadata of the node to the build array in preprocess.