Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
There's no "Rendered entity" field handler in views. We used to have it in D7 (provided by the Entity module).
Proposed resolution
In D8 there's a "Rendered entity" area handler already, so it should not be hard to do the same as a field handler.
Remaining tasks
Commit.
User interface changes
Have a "Rendered entity" field in views UI.
API changes
-
Data model changes
-
Comment | File | Size | Author |
---|---|---|---|
#54 | interdiff.txt | 1.75 KB | dawehner |
#54 | 2632068-54.patch | 17.99 KB | dawehner |
#50 | 2632068-50.patch | 18.24 KB | bojanz |
#47 | 2632068-46.patch | 18.24 KB | bojanz |
| |||
#47 | 2632068-46.patch | 18.24 KB | bojanz |
|
Comments
Comment #2
czigor CreditAttribution: czigor at Liip commentedThis kind of works. Might need some cleanup.
Comment #3
czigor CreditAttribution: czigor at Liip commentedWriting test is in progress.
Comment #4
dawehnerGiven semantic versioning this won't land in 8.0.x but just in 8.1.x
... field handler
There should be a more specific service available now.
Unused
That method is not used
Comment #5
czigor CreditAttribution: czigor at Liip commentedThanks for the review! Tests are still under construction.
I'll fix 1.
2. I'm implementing here \Drupal\views\Entity\Render\EntityTranslationRenderTrait::getEntityManager() which should return a \Drupal\Core\Entity\EntityManagerInterface. Until it's not fixed there I can't really do anything about it.
3-4: I need to implement these too because they are abstract methods of \Drupal\views\Entity\Render\EntityTranslationRenderTrait.
Comment #6
dawehnerOh yeah you are right,
Comment #7
czigor CreditAttribution: czigor at Liip commentedCredits go to @eager_hun for providing a connection to the world wide web.
Comment #8
dawehnerIMHO we could use the API directly, so using
EntityViewMode::create()->save()
andEntityViewDisplay::create()->save()
.Its just unnecessary HTTP requests without any benefit, IMHO
Comment #9
dawehnerGiven that people might want to use it in 8.0.x already, we backported it to https://github.com/fago/entity/pull/19
Comment #10
czigor CreditAttribution: czigor at Liip commentedThanks, that makes perfect sense. Number of lines in test has been drastically reduced.
Comment #11
jibranI think this is ready other then this minor feedback.
AFAICS we are not using this method so this can be removed.
Comment #12
czigor CreditAttribution: czigor at Liip commented:) Yes, it is, see comment #5 -> 3-4.
Comment #13
bojanz CreditAttribution: bojanz at Centarro commentedI want to try and convert that test to a kernel one, for speed.
Comment #14
dawehnerThank you @bojanz!!
Comment #15
mglamanHere's my attempt at porting it to ViewKernelTestBase
Comment #17
dawehnerConverted the test to use entity_test entities, and some more changes.
Comment #18
bojanz CreditAttribution: bojanz at Centarro commentedWe're good to go.
Made some final code style tweaks.
Comment #19
bojanz CreditAttribution: bojanz at Centarro commentedActually the test had unused imports.
Comment #20
bojanz CreditAttribution: bojanz at Centarro commentedThe calculateDependencies part was requested by dawehner. Fixed a few comments along the way.
Now really RTBC?
Comment #22
jibranWhy not use $entity->getEntityTypeId() instead of $this->getEntityTypeId()?
Comment #23
dawehnerI'm okay with that, but the testbot isn't.
Comment #24
bojanz CreditAttribution: bojanz at Centarro commentedBah.
Comment #25
dawehnerHa, I'm confused because there is also getEntityType() on there.
Comment #26
dawehnerYeah nevermind the trait adds this.
Comment #27
alexpottI think we should add some more test coverage...
So these views are uncacheable?
Comment #28
digitaldonkey CreditAttribution: digitaldonkey commentedI can Confirm the patch working.
"Uncachable" sounds like a very bad Idea. Didn't check that yet.
But I consider this a an essential feature of views as everybody should use viemodes as much as possible (think about your themers ;) ).
It will also enable e.g. Table layout with rendered entities.
So I hope It will be ready in 8.3.
Comment #29
czigor CreditAttribution: czigor at Liip commentedCaching changed to tags-based.
Translation and cache-tag tests are also coming soon.
Comment #30
michaellenahan CreditAttribution: michaellenahan at erdfisch commentedI would like to test this manually, but I'm not sure how to manually test the fact that the rendered entity is being cached.
Comment #31
digitaldonkey CreditAttribution: digitaldonkey as a volunteer and commentedTested on Drupal VDD with Drupal 8-1.x
Works as expected. Cache entries are created in cache table (tag based). --> Seems to work :)
Comment #32
jcnventura CreditAttribution: jcnventura at Wunder commentedWe looked at this in the Frankfurt sprint.
Comment #33
czigor CreditAttribution: czigor at Liip commentedComment #34
dawehnerIMHO we should set #access to
$entity->access('view', NULL, TRUE);
Comment #35
dawehnerComment #36
dawehner@czigor Did you managed to add some translation / cache-tags tests?
Comment #37
czigor CreditAttribution: czigor at Liip commentedSorry, no. It's high on my list, but I still can't say when I will find the time for it. Feel free to take it.
Comment #38
dawehnerAlright, I'll give it a try. Thanks you for your really quick response.
Comment #39
jibranI think we need an empty update hook to clear the views data cache.
Comment #40
dawehnerTrue, I guess. On the other hand, nothing is broken without it. The new feature will just appear at some point ;)
Comment #41
dawehnerSure, here it is.
Comment #42
mohit_aghera CreditAttribution: mohit_aghera as a volunteer and at Axelerant commentedI've tested patch #41 on locally.
It seems working fine. Content is also rendered in proper display format. Screenshot attached.
Comment #45
bojanz CreditAttribution: bojanz at Centarro commentedWeird, it applies with fuzz locally. Here's a reroll anyway.
Comment #47
bojanz CreditAttribution: bojanz at Centarro commentedNow with less trash.
Comment #50
bojanz CreditAttribution: bojanz at Centarro commentedmglaman caught the duplicate update number.
Comment #51
bojanz CreditAttribution: bojanz at Centarro commentedBack to RTBC.
Comment #52
dawehnerComment #53
catchCan't imagine this is necessary for entity_test.
Copy/paste comments - no nodes or body?
Also copy/paste comments?
Comment #54
dawehnerOh yeah , there we go.
Comment #55
bojanz CreditAttribution: bojanz at Centarro commentedSorry about that, catch.
#54 addresses #53, a search shows no more mentions of "node". Let's give it another shot.
Comment #57
catchThat's better. Committed/pushed to 8.1.x, thanks!
Comment #59
yannickooOh that's funny, I have created a module for that 4 months ago - well done guys :)
Comment #60
xjm