Problem/Motivation

Our AV Portal media types have field widgets that are using AJAX. On the media edit form, when the source field is not yet filled in by the user, the widget AJAX calls produce this error:

TypeError: Drupal\media_avportal\AvPortalClient::getResource(): Argument #1 ($ref) must be of type string, null given, called in /src/Plugin/Validation/Constraint/AvPortalResourceConstraintValidator.php on line 59 in Drupal\media_avportal\AvPortalClient->getResource() (line 121 of /src/AvPortalClient.php).

Proposed resolution

The validator should make sure that the value passed to AvPortalClient::getResource() is a string and it should not validate the URL if the source field is empty.

CommentFileSizeAuthor
#5 3391935-5.patch721 byteskeszthelyi
#3 3391935-3.patch1.56 KBkeszthelyi
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

keszthelyi created an issue. See original summary.

keszthelyi’s picture

StatusFileSize
new1.56 KB

Patch from 3c71bdcd

keszthelyi’s picture

Status: Active » Needs review
keszthelyi’s picture

StatusFileSize
new721 bytes

Patch from 77844c29

keszthelyi’s picture

Removed the string check from #3 as we can be sure it's a string if not NULL.

dxvargas’s picture

Status: Needs review » Reviewed & tested by the community

It makes sense to not validate an empty source field.
I've tested with Drupal core 10, 1.x-dev and using a multiple taxonomy term reference field. Before when adding a new item I had this error. After applying the patch the error was gone.

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

hernani’s picture

Version: 8.x-1.x-dev » 2.x-dev
Status: Reviewed & tested by the community » Fixed

Merged into 2.x

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • hernani committed 8f380438 on 2.x authored by keszthelyi
    Issue #3391935: PHP error on AJAX calls when validating resource URLs
    

Status: Fixed » Closed (fixed)

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