When using (managed) file/image field, it is not possible to save an external entity

Created on 14 August 2025, about 1 month ago

Problem/Motivation

When the file field mapper is used to map an external URI as a Drupal managed file, it is not possible to edit an external entity instance and save it:

TypeError: Cannot access offset of type string on string in Drupal\Core\Field\WidgetBase->extractFormValues() (line 504 of core/lib/Drupal/Core/Field/WidgetBase.php).

Drupal\file\Plugin\Field\FieldWidget\FileWidget->extractFormValues() (Line: 256)
Drupal\Core\Entity\Entity\EntityFormDisplay->extractFormValues() (Line: 334)
Drupal\Core\Entity\ContentEntityForm->copyFormValuesToEntity() (Line: 301)
Drupal\Core\Entity\EntityForm->buildEntity() (Line: 155)
Drupal\Core\Entity\ContentEntityForm->buildEntity() (Line: 186)
Drupal\Core\Entity\ContentEntityForm->validateForm()
call_user_func_array() (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers() (Line: 275)
Drupal\Core\Form\FormValidator->doValidateForm() (Line: 118)
Drupal\Core\Form\FormValidator->validateForm() (Line: 585)
Drupal\Core\Form\FormBuilder->processForm() (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 622)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 53)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 715)
Drupal\Core\DrupalKernel->handle() (Line: 19)

At the beginning, Drupal was trying to validate an external file identifier while the file field mapper uses tricked file identifiers. It lead to SQL error. To get around that and rather than providing an interface to modify a file, a text field was provided to allow external URI (real URI) editing and saving. But even with that change, Drupal still works as if the field was a managed_file field, leading to the error above.

Steps to reproduce

Create an external entity type with a file upload field (managed_file), map it to an external URI using the file field mapper plugin. Edit an external entity instance and try to save it.

Proposed resolution

Investigate why Drupal is still working with a managed_file (\Drupal\file\Plugin\Field\FieldWidget\FileWidget) and find a way to make it work with a textfield instead. Also take into account additional field properties such as "alt" or "title" for images.

Remaining tasks

Investigate.

User interface changes

To be determined.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇫🇷France guignonv Montpellier

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

Comments & Activities

  • Issue created by @guignonv
  • 🇫🇷France guignonv Montpellier
  • 🇮🇳India divyansh.gupta Jaipur

    Working on it

  • 🇫🇷France guignonv Montpellier

    @divyansh.gupta
    Sorry I should have put that I was working on it. My bad, and my apologies. I just committed a fix. However, there are still things to fix. It is not possible to edit the file/image field settings now.
    And the code needs to be tested: we need to make sure it does not affect existing file/image fields validation and use on nodes, and tests other aspects. The UI also needs to be improved to allow to add/remove URIs.

    Please feel free to work on the new code now, I don't have time right now and I'm moving on something else.

  • 🇮🇳India divyansh.gupta Jaipur

    Ok @guignonv, no worries i will work on the remaining fixes.

  • 🇮🇳India divyansh.gupta Jaipur

    Sorry @guignonv, but i am not able to use this module i am seeing this error again and again

    Error message: 
    External entities requires the galbar/jsonpath library.

    Although i installed galbar/jsonpath mutliple times.

  • 🇫🇷France guignonv Montpellier

    If you install using Composer, it should be installed automatically. If not, then you need to put it in your installation root in /vendor/galbar/.
    It should look like that:

    └── jsonpath
        ├── CHANGELOG.md
        ├── CONTRIBUTING.md
        ├── LICENSE
        ├── NOTICE
        ├── README.md
        ├── app
        │   ├── docgen.php
        │   └── test.php
        ├── composer.json
        ├── docs
        ├── phpunit.xml.dist
        ├── src
        │   └── Galbar
        │       ├── JsonPath
        │       │   ├── Expression
        │       │   │   ├── ArrayInterval.php
        │       │   │   ├── BooleanExpression.php
        │       │   │   ├── ChildNameList.php
        │       │   │   ├── Comparison.php
        │       │   │   ├── InArray.php
        │       │   │   ├── IndexList.php
        │       │   │   └── Value.php
        │       │   ├── InvalidJsonException.php
        │       │   ├── InvalidJsonPathException.php
        │       │   ├── JsonObject.php
        │       │   ├── JsonPath.php
        │       │   ├── Language
        │       │   │   ├── ChildSelector.php
        │       │   │   ├── Regex.php
        │       │   │   └── Token.php
        │       │   └── Operation
        │       │       ├── GetChild.php
        │       │       ├── GetRecursive.php
        │       │       └── SelectChildren.php
        │       └── Utilities
        │           └── ArraySlice.php
        └── tests
            ├── Galbar
            │   ├── JsonPath
            │   │   ├── JsonObjectIssue37Test.php
            │   │   ├── JsonObjectIssue64Test.php
            │   │   ├── JsonObjectLengthOperatorTest.php
            │   │   ├── JsonObjectTest.php
            │   │   └── JsonPathKeyRegexMatchTest.php
            │   └── Utilities
            │       └── ArraySliceTest.php
            └── bootstrap.php
    
Production build 0.71.5 2024