Error when embedding non-existing Media in WYSIWYG editor

Created on 10 December 2023, about 1 year ago
Updated 17 May 2024, 8 months ago

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.

πŸ› Bug report
Status

Fixed

Version

1.1

Component

Code

Created by

πŸ‡²πŸ‡©Moldova sandzel Chisinau

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @sandzel
  • πŸ‡²πŸ‡©Moldova sandzel Chisinau
  • πŸ‡ΊπŸ‡ΈUnited States scott_earnest

    Thank you @sandzel for the patch!

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

    RTBC +1

  • Issue was unassigned.
  • Status changed to Needs review 10 months ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 10 months ago
    Composer require-dev failure
  • πŸ‡ΊπŸ‡ΈUnited States joshf

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

  • Status changed to Postponed: needs info 9 months ago
  • πŸ‡­πŸ‡ΊHungary Balu Ertl Budapest πŸ‡ͺπŸ‡Ί

    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”:



    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. Also tested with both enabled and disabled on-site storing of asset files (a feature added in 1.1.x) but still worked as expected.

    Apparently we need a more detailed list of reproduction steps to get closer to the circumstances the reporter had.

  • Status changed to RTBC 9 months ago
  • πŸ‡­πŸ‡ΊHungary Balu Ertl Budapest πŸ‡ͺπŸ‡Ί

    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.

  • Pipeline finished with Failed
    9 months ago
    Total: 1397s
    #160853
  • Pipeline finished with Failed
    9 months ago
    Total: 1440s
    #160854
  • Pipeline finished with Failed
    9 months ago
    Total: 1405s
    #160858
  • Pipeline finished with Skipped
    9 months ago
    #163003
  • First commit to issue fork.
  • Status changed to Fixed 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States japerry KVUO
  • πŸ‡ΊπŸ‡ΈUnited States japerry KVUO

    Also backported to 1.0.x

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

Production build 0.71.5 2024