Problem/Motivation
The existing StringFormatter provides a setting to link to the entity. This is commonly used in views where the title links to the entity and the operations links are used to provide links to edit.
It is more and more common as a pattern to link the title to the edit form within a CMS, and we plan to do this in Drupal CMS 2.0. Although you can do this manually, it is a bit of a workaround and is not very tidy.
It would be really useful to have the option to link the title to the edit form directly, and that could be used in admin views by default.
Proposed resolution
When the link to content setting is enabled, provide an option for whether to link to view or edit. Proposed screenshot below. Upgrade path would set all existing instances to 'View' to match the current behaviour.
Remaining tasks
TBC
User interface changes
Before:

After:

Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
TBC
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | Screenshot 2025-10-01 at 7.01.50 am.png | 16.84 KB | pameeela |
| #10 | Screenshot 2025-10-01 at 7.01.44 am.png | 9 KB | pameeela |
Issue fork drupal-3544339
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:
- 3544339-add-support-in
changes, plain diff MR !13340
Comments
Comment #2
pameeela commentedComment #3
pameeela commentedDiscussed with @lauriii and we'd love to see this get into 11.3, so we can do this properly in Drupal CMS 2.0. The current workaround of using the 'Link to edit' field and rewriting the title to use that is fragile and likely to cause issues in some situations.
Comment #4
pameeela commentedComment #6
ckrinaAs a UX Manager I approve the change: it will help apply the more standard pattern outside Drupal, and give the capacity to existing sites&users to keep what they are used to.
Edit: As a small note, I discussed with @pameeela I'd change the "Link to view" / "Link to edit" to "Link to view content " / "Link to edit content" because even if it is repetitive it makes it obvious to what it is referring to and allows to remove the description, making the UI simpler.
Comment #7
pameeela commentedComment #9
phenaproximaAfter some discussion with @catch, I decided to add the link relationship as an additional configuration key, because trying to convert
link_to_entityinto a nullable string would put us into what can only be described as the 10th circle of update path hell.But adding a new config key is straightforward, so I think this is ready for review.
Comment #10
pameeela commentedUpdated screenshots.
Comment #11
rodrigoaguileraI came across a similar problem but for entity references so I created a contrib module for that.
https://www.drupal.org/project/entity_link_formatter
I wonder if this change could allow for some extensibility to allow `link_rel` to be the name of a valid link template for other modules to be able to use the formatter without extending with a new class and adding a new schema.
Comment #12
phenaproxima@rodrigoaguilera, yes, a module could extend this by implementing hook_config_schema_alter() to change the options available to the validation constraint, then probably a targeted form alter to put additional options into the settings form.
Comment #13
smustgrave commentedBelieve this will need an upgrade path for existing fields right.
Comment #14
phenaproxima@smustgrave, this was implemented as a new setting specifically to avoid the need for an upgrade path. If the setting isn't there, it pretty much should continue doing what it already does. What leads you to believe it needs an upgrade path?
Comment #15
smustgrave commentedIs this not a new setting key that would appear in the config export?
Comment #16
phenaproximaIt is, but that why does that necessitate an upgrade path? It will appear in exports as the config is re-saved, and re-exported, over time.
Comment #17
smustgrave commentedAlways been under the impression under the scenario
Config export
Apply the MR
Resave the form or settings making no changes
Config export if the config changes then we need an upgrade path
Comment #18
phenaproximaIn my experience as a core developer, the reason to do an update path is if the code will not function properly unless the config is updated. Or if making a backwards compatibility layer is deemed too clumsy or otherwise undesirable. This is much more likely to happen when changing existing config structures, not when adding a new setting.
Neither of those is the case here. If the
link_relsetting is not already known, it defaults tocanonicaland keeps working as expected. There is no need for a BC layer, since this is a new feature.So unless I'm missing something, this doesn't need an upgrade path (whew!). 😅
Comment #19
longwaveAdded some questions to the MR.
Comment #20
phenaproximaOK -- I decided to make
link_relnon-nullable and default tocanonical. That avoids the painful update path, in this issue at least.Comment #21
dcam commentedPersonally, I don't like the possibility of having a single radio element as in the case of there not being an
edit-formlink template. I don't know if that was considered when the usability review was done or if it matters.Was it a conscious decision to continue hiding the link form elements if there is no
canonicallink template? There's no discussion about it. This feels like a another issue waiting to happen when someone eventually wants to link to anedit-formroute for an entity type that has nocanonicalroute.This was the response to the question of whether other link templates could be added as options without having to override the class. If I'm not mistaken, then this isn't true anymore. It's caused by the
match()statement insettingsSummary(). If someone altered the form to add another template, then the summary would throw anUnhandledMatchErroron the display form. Is there a way around it?Comment #23
smustgrave commented@phenaproxima thoughts on the last question?
Comment #24
phenaproximaThat's a good point. I think it's fine to add a
defaultbranch to thematchexpression to handle this gracefully, and I've implemented that in the MR.Comment #25
smustgrave commentedRebased this with main but caused numerous test failures.
Comment #26
phenaproximaTests fixed.
Comment #27
dwwIn principle, huge +1 to this. I often do weirdness like making the entity ID a hidden column in the view, then re-writing the title column as a link and using Twig into
[entity_type]/{{ id }}/editor something. This would be much cleaner.Haven't closely looked at the MR, but wanted to ask here in the issue: how does this interact with media entities and the
standalone_urlsetting? I believe that defaults to FALSE, so media entities have bothcanonicalandedit-formpointing to the sameedit-formroute. Isn't that going to be confusing AF for people in the context of this issue? 😬Doesn't seem particularly clean for this Field API plugin to be aware of these internals and peculiarities of media entities. But makes me wonder if we need to make it easier for Media to alter this plugin when used with media entities?
To that end, echoing the concerns of @dcam in #21 and @joachim in the MR thread about what happens to this UI when there's only 1 radio option.
My OOP brain went to having something like
protected function getAvailableLinkOptions(): arrayin the plugin. Instead ofStringFormatter::settingsForm()directly trying to populate#optionsas it's creating the form, it should call out to the protected helper. If thecount()of the return value is > 1, we present the radios and add#states. Otherwise, maybe we just mention it in the#descriptionof thelink_to_entityelement or something? Or perhaps the'link_relelement is only#markup(that still only appears with #states) in this case to mention what kind of link you'll get?Comment #28
phenaproximaThis should be fixed now. The intention is that the new setting is hidden if you only have one option, in which case the existing "link to entity" checkbox acts the way it currently does.
The media stuff is a good point, but not in scope for this issue I think. We should probably open a follow-up to deal with that.
Comment #29
smustgrave commentedOpened #3584708: New setting in StringFormatter may impact media standalone_url setting
Tested this MR and confirmed the setting works as advertised. Logged in with a role that couldn't edit and don't see the setting anymore.
Believe that was the only feedback so will mark.
Comment #33
larowlanCommitted to main and backported to 11.x
Added and published a change record
Thanks all
Comment #35
penyaskitoEdited the change record to add a note about https://git.drupalcode.org/project/drupal/-/merge_requests/13340#note_74...
🎉🎉🎉