Problem/Motivation
#2342045: Standard views base fields need to use same rendering as Field UI fields, for formatting, access checking, and translation consistency is a critical issue, which changes entity base fields like node.title to be full entity fields, meaning they will use Field Formatters instead of custom Views formatters. This also makes them behave like entity fields for translation purposes (otherwise, multilingual field-based views are broken), which is why that is a critical issue and something we really need to do.
However, making that change loses functionality that fields like node.title had to "link this field to its entity". This is used in probably at least half of all field-based views (you usually want to display the node title as a link to the node, for instance). So, we can't really just lose that feature.
Proposed resolution
The proposal is that all "short string" entity field formatters would have a checkbox to link the field to the entity. This way, when node.title and other base entity fields are converted to being full entity fields in Views, using standard Entity Field formatters, they will inherit the "link to entity" checkbox" setting.
We probably don't need this on "long string" field formatters -- for instance you probably don't often need the ability to link the body to the node (you could do it in a view anyway with a Rewrite if you really needed it). Or on fields that aren't strings (normally you want string-based link text). So we'll just do it for "short string fields".
Remaining tasks
User interface changes
All "short field" entity field formatters will have a checkbox setting to link the field to the entity. This will be usable in Views, Entity display modes, etc.
API changes
There is an addition to the config schema for the string formatter for entity string fields.
Beta phase evaluation
| Issue category | Task, because its adds a new feature. (Yes, this is a feature, but it's needed to add back a necessary feature that will go away if the blocked critical is resolved.) |
|---|---|
| Issue priority | Major because ... it unblocks a critical? |
| Disruption | Not disruptive, because its adding a feature, no public API change |
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | Screenshot 2014-12-12 19.48.16.png | 18.57 KB | larowlan |
| #25 | Screenshot 2014-12-12 19.45.23.png | 11.09 KB | larowlan |
| #25 | Screenshot 2014-12-12 19.44.35.png | 17.25 KB | larowlan |
| #24 | interdiff.txt | 9.6 KB | dawehner |
| #24 | 2387019-24.patch | 18.29 KB | dawehner |
Comments
Comment #1
dawehner.
Comment #2
amateescu commentedYou need to take into account that $entity->urlInfo() can throw an exception. See #2355245: ER's label formatter needs to take into account that $entity->urlInfo() might throw an exception.
Comment #4
dawehnerThank you for the tip!
Comment #5
dawehnerFixed the schema failures.
Comment #7
amateescu commented#type should be first?
Shouldn't this be "Links to ..."? We're not displaying an action here.
$entity = $items->getEntity().
Where is this used?
Comment #8
gábor hojtsyThis is a fabulous issue. Thanks so much for doing this. Only one comment.
This is called link_to_entity in comment, etc. (and prior to that link_to_node, etc) in entity type specific cases. So using link_to_entity here would be consistent.
Comment #9
yched commentedAwesome, @dawehner++
A couple nitpicks:
Yeah, only used for the settingsForm() / settingsSummary(), meaning 1% of actual runtime uses of the class.
Would it make sense to have a @todo to make it lazy ?
No biggie I guess since any request that uses a field formatter will have the entity_manager instantiated anyway. Feel free to ignore :-)
Might be worth a comment that the link option does not make sense for the other field types the formatter supports.
Also, for symmetry, we should probably add the same condition on "field type === string" than in settingsForm() & viewElements(). If I manually edit my config to switch the 'entity_link' setting, it should still have no effect on other field types.
The image formatter says "Linked to .." in the summary - let's stay consistent with what's already there ?
"Link to" is fine in the form since, there, it's about an action, but in the summary it's about a status.
You can use $entity = $items->getEntity(), it's shorter / clearer :-)
Also, since this will be the same for all deltas, all of this ('entity_link' setting, link template, entity URL) could be computed once and for all outside the foreach ? (using the link option on a multi-valued string is likely to be a rare use case anyway, but well...)
Comment #11
dawehnerThank you so much for the quick reviews!
Well, I went with a label similar with the
ImageFormatterexample, which is "Link image to ...".Note: The AssertContentTrait is using
getUrl()when it parses the output. This patch now just moves the code fromWebTestBasealso toAssertContentTrait.Oh! This is much better!
This should also fix both failures.
Decided to went with that, good suggestion.
Agreed :) I think not injection depdencies is just a sign for lazyness :)
... if you manually update your config, good luck anyway :) But I agree, let's make it consistent.
Good suggestion!
Good suggestion as well.
Comment #14
dawehnerAlright, let's fix the schema problem.
Comment #16
dawehnerKilled that.
Comment #17
dawehner.
Comment #19
jhodgdonClarifying issue summary
Comment #20
dawehnerAlright, talked with yched about a different approach, let's see how this works.d
Comment #21
dawehnerAs we discused, this issue is needed in order to resolve the critical D8MI issue.
No interdiff, because its a full new approach, the interdiff does not really tell you anything.
Comment #22
yched commentedActually, "raw" is probably not a great idea, as it kind of hints "non-escaped, non-sanitized", which is not the right message to send for a formatter :-)
Since this formatter is kind of the simplest one you might think of (just prints the checkPlained value), maybe 'basic_formatter' ?
No need to check for the field type anymore :-)
Comment #23
berdirThis will affect existing view display entities if you were using string for string_long fields.
Just pointing out...
My only other thing was the same field definition check that @yched already pointed out. i think it's good to remove that, so that if you allow your field type for that formatter (formatter alter hook), then it works for that as well.
Comment #24
dawehnerThank you for the feedback!
Comment #25
larowlanReally love this feature.
Reviewed code, couldn't fault it.
Manual review screenshots below.
I hate to be difficult - but changing all that config from 'string' to 'basic_string' is going to mean people in contrib land will have to do the same.
Any reason why we couldn't leave it as string and then make the new one 'string_link' ?
If there's a reason, then I think this is rtbc.

Comment #26
larowlanComment #27
yched commentedSo the reasoning was that, for 'string' field type, we want only one formatter which optionally lets you link or not, rather than two formatters (one that links and one that doesn't). That's for consistency with how "link or not" works for image fields : it's an option within the image formatter.
Then it makes sense that this single formatter for the 'string' field type is the formatter that we call 'string', rather than "the 'string' formatter is used by a couple field types but *not* the 'string' field type, which in fact uses a formatter named 'string_link'".
Comment #28
yched commentedSilly question : would it make sense to have 'string_long' field type also use the 'string' formatter (the one that can link) ?
I kind of like the consistency of :
- 'string' / 'string_long' field types --> 'string' formatter
- 'email' / 'phone' / ... field types -> 'basic_string' formatter
But no strong opinion...
Comment #29
yched commentedre: #28 - discused with @dawehner, there's no use case for linking on long strings.
Current patch is RTBC as far as I'm concerned :-)
Comment #30
larowlanThanks @yched that makes sense - +1 RTBC from me then
Comment #31
catchLooks good to me. I'd not have minded keeping the same name, but this is also a tiny update for contrib/custom code to make so I think that's OK given the issue is critical.
Not committing yet just so this has a bit longer than an hour at RTBC.
Comment #32
catchWill need some kind of change record though for that.
Comment #33
dawehnerSure, added the change record.
Comment #34
catchCommitted/pushed to 8.0.x, thanks!
Comment #35
gábor hojtsySome retroactive D8MI tags.