Problem/Motivation
While looking at the logs I noticed that on our production site there were quite a few errors related to the following.
The URL that triggered the error looks like this: /entity-embed/edit-embedded/media/5af3cba5-8dc3-474c-9b21-70962d733e77
The error it outputs:
Error: Call to a member function id() on null in Drupal\entity_embed\Controller\EditEmbeddedEntity->edit() (line 22 of modules/contrib/entity_embed/src/Controller/EditEmbeddedEntity.php).
Steps to reproduce
1. Try to access a non-existing media entity by the route /entity-embed/edit-embedded/media/5af3cba5-8dc3-474c-9b21-70962d733e77 where the media id does not exist.
2. Notice the error in the logs
Proposed resolution
The following is a quick fix, it can probably be improved significant:
In the file EditEmbeddedEntitiy.php Change the line 22:
return $this->redirect("entity.$type.edit_form", [$type => $entity->id()]);
to
return $entity
? $this->redirect("entity.$type.edit_form", [$type => $entity->id()])
: $this->redirect('system.404');
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | Screenshot from 2023-11-20 19-58-28.png | 122.82 KB | vivek panicker |
| #7 | Screenshot from 2023-11-20 19-58-23.png | 181.18 KB | vivek panicker |
| #6 | Screenshot from 2023-11-20 19-40-44.png | 124.94 KB | vivek panicker |
| #6 | Screenshot from 2023-11-20 19-38-37.png | 624.69 KB | vivek panicker |
| #3 | issue-3402443-php-error-call-fixes.patch | 651 bytes | viren18febs |
Issue fork entity_embed-3402443
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
viren18febs commentedI have updated the code as per solution provided & added patch, please review.
Comment #4
dasj19 commentedPatch looks good
Comment #5
vivek panicker commentedChange looks good.
Comment #6
vivek panicker commentedHowever under what situation are we arriving at this condition?
I created a node, embedded it in an article page, then deleted the node.
When I load the article page I see this:

Code gets stopeed here:

In the error logs I get a proper log:
So we would need some steps to reproduce the issue first.
Comment #7
vivek panicker commentedThe issue can be reproduced in the following way:
- Embed content A inside content B
- Delete content A
- Edit content B
- Now click on edit button for embedded content.
- See the error mentioned in the issue description in the log.
I applied the patch and checked.
We see the same popup that we see when we click on the embed button.
So the patch is working fine and we can move this issue forward.
Comment #8
vivek panicker commentedComment #12
dave reid