Updated: Comment #0
Problem/Motivation
We have _entity_list, _entity_form already, lets add _entity_view to cut down on boilerplate code for viewing an entity
Proposed resolution
Add an _entity_view option for routing of the form entity_type.view_mode
Remaining tasks
Write the patch
Tests
Review
User interface changes
None
API changes
No need for boilerplate code for viewing an entity
Related Issues
#1987898: Convert user_view_page() to a new style controller
#2008356: Provide a _entity_list route default to replace Controller\EntityListController and mimic _entity_form
#731724: Convert comment settings into a field to make them work with CMI and non-node entities
Comment | File | Size | Author |
---|---|---|---|
#29 | _entity_view-2040265.29.interdiff.txt | 867 bytes | larowlan |
#29 | _entity_view-2040265.29.patch | 13.76 KB | larowlan |
#27 | _entity_view-2040265.27.interdiff.txt | 6.98 KB | larowlan |
#27 | _entity_view-2040265.27.patch | 13.76 KB | larowlan |
#19 | _entity_view-2040265.19.real_.interdiff.txt | 6.52 KB | larowlan |
Comments
Comment #1
larowlanIt pains me to add another web test, but I think we have to given we're concerned with rendering output here.
Comment #2
jibranEmpty patch
Comment #3
larowlandoh!
Comment #4
BerdirHaving $langcode here seems useless, when you can't set it?
I'd rather either set the langcode to anguageManager->getLanguage(Language::TYPE_CONTENT)->id or actually just get the corresponding translation ($entity->getTranslation(.. content langcode..) if $entity implements the TranslatableInterface and hasTranslation (content langcode).
You want to check with @plach what makes sense. But I think we want to get deprecate $langcode arguments in favor of passing the right entity translation around. But I guess we can't actually remove those arguments anymore?
Comment #5
larowlan@berdir you can set the langcode in your routing.yml
Comment #6
dawehnerThis works in most cases, but what happens if you have specified a different variable name? See entityConverter
Is there a specific reason why you haven't wrote a unit test?
Comment #7
larowlanWell I figured render array = web test. Also I really want this route for #731724: Convert comment settings into a field to make them work with CMI and non-node entities so we can use entity_test_render instead of user for our 'non-node' comment tests. To be honest, when that goes in, this test can become a unit test instead. So I guess it could be just a unit test.
Good call on the variable names. I will incorporate that too.
Comment #8
andypostawesome idea. let the scope of patch focus on route and probably language for follow-up
Comment #9
larowlanSo this
a) handles converters (eg $options['converters'])
b) adds test coverage for converters
c) adds a unit test for the controller
Note the web test is retained but can/should be removed once we start using _entity_view in web tests in #731724: Convert comment settings into a field to make them work with CMI and non-node entities with a comment field attached to an entity_test_render entity.
Comment #10
dawehnerJust to note, this will certainly break when #1943846: Improve ParamConverterManager and developer experience for ParamConverters is done.
Comment #11
tim.plunkett#9: _entity_view-2040265.9.patch queued for re-testing.
Comment #12
tim.plunkettIt didn't break because it just adds onto EntityRouteEnhancer instead of adding a new top level one.
This blocks a half dozen conversions in #1971384: [META] Convert page callbacks to controllers, which is a critical, so this is as well.
(Think /node//%, user/%, etc)
Comment #13
alexpottWhy do only set be reference in the first instance?
Comment #14
alexpottAnd do we have any test coverage of this code?
Comment #15
larowlan1) you're right they should both be by reference
2) only a unit test, but I will expand the Web test to cover that scenario too
Comment #16
tim.plunkettComment #17
larowlanFail, Pass, Interdiff
Web tests++
Turns out it isn't $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT) but $defaults[RouteObjectInterface::ROUTE_OBJECT]
So unit tests passed because they assumed the same thing (wrongly).
Comment #19
larowlanpro tip: when running tests locally, be sure to run them after merging HEAD, not before.
#1943846: Improve ParamConverterManager and developer experience for ParamConverters turned this on its head.
Should be green now.
Comment #20
larowlanComment #21
andypostWhy default value is not bound to 'default'? For the most of cases we will use default view mode of entity assuming it's full
1) do we need conversion of default to full as defaults?
2) do we need tests for that too?
what is a dafults for now? full/default
related: #2006348: Remove default/fallback entity form operation
Comment #22
larowlanHi @andypost
I don't understand your question.
I think you mean you want to be able to use
And have the view mode select the default?
Comment #23
andypostYes, I suppose this needs fallback to 'default' view mode
Comment #24
andypostDiscussed in IRC - the route should use 'full' because it's default in
EntityRenderControllerInterface::view()
Also it would be great to have tests for none-existent view mode
so $view_mode needs 'full' as default
Or maybe
$defaults['view_mode'] = empty($view_mode) ? 'full' : $view_mode;
Comment #25
andypostthis uses 'default' view mode that does not exists
Comment #26
larowlanusing default is ok in a unittest, will add a comment as such.
@andypost++
Comment #27
larowlanAdds the changes discussed at #21 through #26
Comment #29
larowlanphpunit strict warnings ey, wonder why our phpunit config doesn't throw those locally, regardless - fixed
Comment #31
larowlan#29: _entity_view-2040265.29.patch queued for re-testing.
Comment #32
larowlanRest/NodeTest random fails again
Comment #33
tim.plunkettAh, that last interdiff is interesting :)
The changes in #27 look good to me, as do the ones before that.
Comment #34
andypost+1 tortbc
Comment #35
alexpottCommitted 1deffa8 and pushed to 8.x. Thanks!
Similar to https://drupal.org/node/1799642 I think we need a change notice.
Comment #36
yched CreditAttribution: yched commentedSweet - so, isn't there some existing code in HEAD that can be removed now ?
Comment #37
yched CreditAttribution: yched commentedoh, d.o ...
Comment #38
tim.plunkett@yched, issues like #1987898: Convert user_view_page() to a new style controller can now use this.
Comment #39
larowlanChange notice here https://drupal.org/node/2056839
Comment #40
BerdirDon't think it's necessary to put in a whole entity annotation? Should be enough to just say given you have an entity type named whatever?
Can we maybe put in an example of how you'd do it in 7.x?
Comment #41
tstoecklerI don't want to argue in favor of rolling this back or anything, but I just want to note that using the underscore in this way sort of conflicts with the fact that we use the underscore to separate magic attributes like '_account' from actual route parameters. I brought that up there and was told that prefixing arguments with underscores is so far-fetched we shouldn't worry about it. For instance if we were to introduce a menu_get_object()-style '_entity' attribute for routes where it would make sense, this would break.
I don't want to open a whole discussion about this or the (arguably poor) use-case, I just wanted to point out that this is less than ideal.
I also don't have a better suggestion, however.
Comment #42
Crell CreditAttribution: Crell commentedActually... wha? Why is that property $_ prefixed? That doesn't make sense at all...
Comment #43
tim.plunkettsame reason it's $_content, $_controller, $_form, $_entity_list...EDIT: I misread the question, I thought it was about $_entity_view. If you look in EntityRouteEnhancer::enhance(), there is a whole section on normalizing what the entity is.
If you have /foo/{account} to mean the User entity type, it has to use converters to figure that out. I'm not 100% sure why that's done here, or why we don't turn it back into the named param you specify at the end.
Comment #44
larowlanUpdated change notice https://drupal.org/node/2056839
Comment #45.0
(not verified) CreditAttribution: commentedUpdated issue summary.