Error opening the media library when adding a new micro site

Created on 29 August 2024, 5 months ago
Updated 10 September 2024, 4 months ago

Problem/Motivation

While creating a new micro site, I came across an issue with the media fields.
If I try to open the media library without filling in the "Site URL" field I will get the following message:
Oops, something's up. Check your browser's developer console for details.

When checking the Drupal logs I see the following error:

Drupal\Core\Database\InvalidQueryException: Query condition 'site_field_data.site_url IN ()' cannot be empty. in Drupal\Core\Database\Query\Condition->condition() (line 106 of /var/www/html/web/core/lib/Drupal/Core/Database/Query/Condition.php).

Steps to reproduce

  1. Install the "Micro site", "Media" and "Media Library" modules.
  2. Create a new site type with a media field with the "Media library" formatter.
  3. When creating a new micro site, click the button to open the media library in the media field, without filling in the "Site URL" field.

Proposed resolution

The error occurs in the SiteUrlFieldConstraintValidator class when trying to obtain the site_url when it is not filled in, so when the query is executed to check the existence of a micro site it results in the error described.

My proposed solution is to prevent the $site_url variable from being null, if it is empty it should be "".

...
class SiteUrlFieldConstraintValidator extends ConstraintValidator {
  ...
  public function validate($entity, Constraint $constraint) {
     ...
    $site_url = $entity->site_url->value ?? "";
  }
}

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇵🇹Portugal lolgm

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024