Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 299325

Ajax Error when uploading new assets using Media Library module

$
0
0

Problem/Motivation

When uploading a new file using the Media Library module, the "Add File" action fails to upload the file and silently throws a console error. This error occurs every time with every media type for our site.

Steps to reproduce:

  1. Choose a node that contains a media field for editing using the "Add media" button.
  2. In the resulting "Add or select media" lightbox, click the "Choose File" button in the "Add File" section.
  3. Choose a file of the appropriate media type.
  4. At this point, a progress spinner is shown then disappears. Nothing further occurs and the file is not added to the library.
  5. Check the console log to see the Ajax error:
    An AJAX HTTP error occurred.
    
    HTTP Result Code: 200
    
    Debugging information follows.
    
    Path: /media-library?media_library_opener_id=field%3Afield_documents_media_&media_library_allowed_types%5Bbasic_image%5D=basic_image&media_library_allowed_types%5Bdocuments%5D=documents&media_library_allowed_types%5Bicon%5D=icon&media_library_allowed_types%5Blocation_photos%5D=location_photos&media_library_allowed_types%5Bremote_video%5D=remote_video&media_library_selected_type=basic_image&media_library_remaining=1&hash=wFpjTCU6C4We9HKZWN4uK4B2cxaXeEhPCddqHR-vBKQ&media_library_content=1&_wrapper_format=drupal_ajax&ajax_form=1
    
    StatusText: parsererror
    
    ResponseText: Notice: Undefined index: #parents in /app/web/core/modules/media_library/src/Form/AddFormBase.php on line 250
    
    [...]

OS: nginx/1.14.2
Database: 5.5.5-10.1.38-MariaDB
PHP 7.2.15
Drupal 8.7.0

Proposed resolution

Adding a null check to AddFormBase.php:buildEntityFormElement():250 allowed me to successfully upload files (patch file to follow in comments).

-    $parents = $form['#parents'];
+    if (array_key_exists("#parents", $form)) {
+      $parents = $form['#parents'];
+    }
+    else {
+      $parents = [];
+    }

Viewing all articles
Browse latest Browse all 299325

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>