Problem/Motivation
#1043198: Convert view modes to ConfigEntity will introduce an EntityViewMode entity. To keep the patch reasonably focused, it did not touch entity viewing and Field UI's handling of view modes. All of that code still passes $view_mode as a string.
Proposed resolution
Everywhere we have $view_mode in core, that should be an instance of EntityViewMode. That means consuming code just needs entity_load('view_mode', ...) instead of retrieving the entire entity info. Doing this will enable us to split view modes from the entity info. This will in turn allow us do remove the workaround from EntityManager::processDefinition(). Whether that happens here or in another follow-up will be left to be seen.
Remaining tasks
Wait on the other patch.
User interface changes
None.
API changes
Anywhere you see a $view_mode it's a full entity now.
This will need a change notice.
Comments
Comment #1
tim.plunkettI think this should be won't fix. As a consumer of the API, it makes more sense to just use the string name directly.
Comment #2
tstoecklerHmm. I tend to disagree, could you provide some reasoning/examples? Assuming you mean something like the following, I personally think it is a wash DX-wise:
And I personally think, anywhere we can type-hint a proper class is actually a DX win, because now you don't just know that you get some arbitrary string, but you can look up what the heck a "view mode" even is and what you can do with it.
I saw an issue somewhere to pass around langcode in tokens instead of the full language object, which would be the exact opposite of this proposal, conceptually, so it might be that I'm alone with this viewpoint.
Either way, even if we keep passing just a string in e.g. hook_entity_view() (again, assuming that's what you mean), then the invoking code should use entity_load() instead entity_get_info() to get that string, IMO. As stated in the issue summary, that will allow us to rip view modes out of the entity info.
So maybe we should repurpose this issue to do that. Once we've done that we can always fight over what to pass to consumers, that will be a trivial change then.
Comment #3
tim.plunkettBefore:
$build = node_view($node, 'teaser');
After:
Comment #4
tstoecklerTouché :-)
Hmm... I'll have to think about this more, also exactly how we want to decouple view mode information from the entity info. I haven't yet read up on the bundles issue either ...
If you don't mind I'd like to keep this open until we have a clear plan on how we want to achieve that.
Comment #17
smustgrave CreditAttribution: smustgrave at Mobomo commentedWonder with D10 if this is still a needed task?
Comment #18
tstoecklerLet's just close it, I don't think it's relevant anymore.