\Drupal\entity_embed\EntityEmbedDisplay\FieldFormatterEntityEmbedDisplayBase requires the \Drupal\node\Entity\Node class, therefore requiring Node module.

  /**
   * {@inheritdoc}
   */
  public function build() {
    // Create a temporary node object to which our fake field value can be
    // added.
    $node = Node::create(['type' => '_entity_embed']);

Comments

dpi created an issue. See original summary.

dpi’s picture

Issue summary: View changes
oknate’s picture

Proposed 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

oknate’s picture

StatusFileSize
new3.13 KB

Here's solution number 2. I'm not sure if I should have gone number 1 or number 2.

oknate’s picture

Status: Active » Needs review
StatusFileSize
new3.96 KB

I 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.

oknate’s picture

I just had an idea. Can't we just use the entity type that will be embedded?

oknate’s picture

Oh, 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:

I guess the parent in this context must be a content entity,

It seems to work using a config entity as the phony parent.

dpi’s picture

Why 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.

oknate’s picture

At 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.

wim leers’s picture

Wow, nice find. This has been this way since commit 862f82a from 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.

wim leers’s picture

Issue tags: +Needs manual testing

Clarifying what this still needs.

dpi’s picture

Still too hacky for my liking, how about this.

Basically a dummy entity type, uses similar method to contact message.

dpi’s picture

Should have removed bundle from entity values. 😅

wim leers’s picture

Hm, 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! 🙏

oknate’s picture

Status: Needs review » Reviewed & tested by the community

Update 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.

mysql> show tables like '%fake%';
Empty set (0.00 sec)

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.

    'handlers' => [
      'storage' => 'Drupal\\Core\\Entity\\ContentEntityNullStorage',
    ],

  • Wim Leers committed 2cea461 on 8.x-1.x authored by dpi
    Issue #3054873 by oknate, dpi, Wim Leers: Hidden dependency on node...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs manual testing

Thanks, @oknate!

🚢

dpi’s picture

FWIW also passes our internal test suite w/ entity_embed coverage.

Thanks all!

dpi’s picture

wim leers’s picture

#18: lovely :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.