Initialization error with the inline_entity_form module

Created on 26 July 2025, 20 days ago

Problem/Motivation

I want to use the signature_pad field SVG on a referenced content type through the inline_entity_form widget. If I try to create a new referenced content having a signature_pad via the inline_entity_form, I receive this error:

Error: Call to a member function getFileUri() on null in Drupal\signature_pad\Plugin\Field\FieldWidget\SignaturePadWidget->getInitDataSvg() (line 492 of /var/www/html/mysite/modules/contrib/signature_pad/src/Plugin/Field/FieldWidget/SignaturePadWidget.php).

Steps to reproduce

1. Implement signature_pad on Basic page
2. Make the Article content type reference the Basic page with the signature_pad.
3. Use the inline_entity_reference as the form widget for the reference field.
4. As soon as you try to create new content via the reference, it throws the error above.

Proposed resolution

The problematic code is here:

    $file = $imageItem->entity;
    $svg = new \DOMDocument();
    $svg->loadXML(file_get_contents($file->getFileUri()));

The problem occurs because the getInitDataSvg() method that the function implements is trying to access a file entity that doesn't exist yet when creating a new entity by $file = $imageItem->entity;.

A simple null check will solve the problem.

  $file = $imageItem->entity;
  // Add null check here
  if (!$file) { return NULL; }
  $svg = new \DOMDocument();
  $svg->loadXML(file_get_contents($file->getFileUri()));
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇮🇪Ireland marksmith

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

Comments & Activities

  • Issue created by @marksmith
  • 🇪🇸Spain rodrigoaguilera Barcelona

    I committed the suggested change to the 1.x branch from my phone.
    Can you confirm it works?

    Thanks for the detailed bug report and solution.

  • 🇮🇪Ireland marksmith

    Yes, that worked. Thanks!

    Now the initialization problem is solved, but signature_pad still does not really work with inline_entity_forms in the sense that the signatures are not saved, and, if created outside of inline_entity_forms canvas is always loaded as empty. I am aware though that this is another issue, a new feature request: make signature_pad work with inline_entity_forms.

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

Production build 0.71.5 2024