Problem/Motivation

When attempting to insert the following code into the WYSIWYG editor
<drupal-media data-entity-type="media" data-entity-uuid="[some-not-existing-id]" data-embed-code-id="original" data-align="center">&nbsp;</drupal-media>,
an error occurs during node save:
Error: Call to a member function get() on bool in Drupal\acquia_dam_integration_links\AssetDetector\EntityEmbedTextDetector->parseAssetId() (line 124 of modules/contrib/acquia_dam/modules/acquia_dam_integration_links/src/AssetDetector/EntityEmbedTextDetector.php).

This issue arises due to the absence of a check for empty $media before attempting to access its properties.

Steps to reproduce

  1. Insert the provided <drupal-media> code into the WYSIWYG editor.
  2. Save the node.

Proposed resolution

To add a check for empty($media) before attempting to access properties in order to prevent the error mentioned above.

Remaining tasks

  1. Apply the code modification to check for empty($media) before accessing properties.
  2. Test to ensure the issue is resolved.
  3. Review and commit the changes.

User interface changes

No user interface changes are expected.

API changes

No API changes are expected.

Data model changes

No data model changes are expected.

Issue fork acquia_dam-3407783

Command icon 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

sandzel created an issue. See original summary.

sandzel’s picture

StatusFileSize
new740 bytes
scott_earnest’s picture

Thank you @sandzel for the patch!

This is working for us:
- Drupal 10.1.6
- Acquia DAM Version: 1.0.11
- PHP 8.1.18

RTBC +1

joshf’s picture

Assigned: sandzel » Unassigned
Status: Active » Needs review

@sandzel it looks like you're done working on this? Moving to needs review.

baluertl’s picture

Status: Needs review » Postponed (maintainer needs more info)
StatusFileSize
new136.3 KB

Now tested, cannot reproduce on the latest development branch 1.1.x. After saving the content entity with the WYSIWYG field it gets properly redirected to its canonical page where the embedded asset is being displayed while the invalid UUID is represented with a generic placeholder reading “The referenced media source is missing and needs to be re-embedded”:

Screenshot

This message originates from core's MediaEmbed filter plugin which is responsible for processing these <drupal-media …></drupal-media> custom HTML tags you also included as a sample. Interestingly according to Git blame, this entire class hasn't changed for 4 years, so the same protection mechanism should be in place for 10.1.6 which core version @scott_earnest confirmed.

Apparently we need a more detailed list of reproduction steps to get closer to the circumstances the reporter had.
Half an hour wasted due to a missing step in reproduction steps: the Enhanced integration links sub-module must be enabled.

baluertl’s picture

Version: 1.0.x-dev » 1.1.x-dev
Status: Postponed (maintainer needs more info) » Reviewed & tested by the community

Due to the fact that we call \Drupal\Core\Entity\EntityStorageBase::loadByProperties() which always returns an array both on its positive and negative branches of logic (source code) I see checking is_array() somewhat pointless. So I support @sandzel's idea to rather check empty() instead.

japerry made their first commit to this issue’s fork.

  • japerry committed 1ed7dbbb on 1.1.x authored by Balu Ertl
    Issue #3407783 by sandzel: Error when embedding non-existing Media in...
japerry’s picture

Status: Reviewed & tested by the community » Fixed

  • japerry committed 8ec01c38 on 1.0.x authored by Balu Ertl
    Issue #3407783 by sandzel: Error when embedding non-existing Media in...
japerry’s picture

Also backported to 1.0.x

Status: Fixed » Closed (fixed)

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