Closed (fixed)
Project:
Entity Embed
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
15 May 2019 at 10:52 UTC
Updated:
12 Jun 2019 at 17:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
dpiComment #3
oknateProposed resolutions (one of these):
1) Add drupal/node as dependency in the info.yml
2) Add a new entity to entity_embed that is expressly for the purpose of creating the formatter.
3) Use a different entity, such as User (which is more common than Node). Could there be a Drupal site without User module installed?
4) See if there's a way to do the same thing without using an entity
Comment #4
oknateHere's solution number 2. I'm not sure if I should have gone number 1 or number 2.
Comment #5
oknateI think for number 2, we'd have to install the entity to pass that test. This would mean we'd have a useless database table added. Is there any way around that? I don't think the database table hurts anything, but it has no purpose other than legitimizing our content entity.
Comment #6
oknateI just had an idea. Can't we just use the entity type that will be embedded?
Comment #7
oknateOh, I guess the parent in this context must be a content entity, but the embed could be another type of entity since we're rendering a field on an entity, such as a config entity which isn't fieldable, so we can't just use the same type as the embed.
Update: I don't think this is true:
It seems to work using a config entity as the phony parent.
Comment #8
dpiWhy is requiring a fully formed entity required? Fake it, or do it a different way. It see this as very smelly code, admittedly haven't looked at alternatives.
Comment #9
oknateAt least when I was testing, it seems the reason it's done the way it's done is that entity reference formatters call getEntity on the field item list, somewhere in here:
$formatter->prepareView([$node->id() => $items]);It looks like a non content entity works though. Since we already have a dependency on embed, maybe we could use the EmbedButton entity.
I'm surprised this worked.
Comment #10
wim leersWow, nice find. This has been this way since commit
862f82afrom May 30, 2014. Five years ago in eight days!I think this is … very hairy. But obviously a pre-existing problem. This makes it less coupled, so is a step in the right direction. If @dpi confirms this works, I'm okay with committing this.
Comment #11
wim leersClarifying what this still needs.
Comment #12
dpiStill too hacky for my liking, how about this.
Basically a dummy entity type, uses similar method to contact message.
Comment #13
dpiShould have removed bundle from entity values. 😅
Comment #14
wim leersHm, interesting. All of this is definitely very smelly :P
So now the tables have turned: rather than @dpi needing to approve @oknate's proposal, now @oknate needs to approve @dpi's proposal :)
Many thanks to the both of you! 🙏
Comment #15
oknateUpdate hook ran fine, and it doesn't create a table, so it solves my major problem with proposal number 2. I also find the name nicely self-explaining.
I tested it manually and it works fine. I ran it through coder sniffer and didn't see anything to change.
This is awesome. I didn't know there was a null ContentEntityNullStorage. I can think of several times over the last few years when this would have been useful.
Comment #17
wim leersThanks, @oknate!
🚢
Comment #18
dpiFWIW also passes our internal test suite w/ entity_embed coverage.
Thanks all!
Comment #19
dpiComment #20
wim leers#18: lovely :)