Problem/Motivation

Message Error: Call to undefined method Drupal\media_library\Form\FileUploadForm::getEntity() in _image_field_caption_widget_process() (line 50 of /Applications/XAMPP/xamppfiles/htdocs/eg-blog/web/modules/contrib/image_field_caption/image_field_caption.module)

This error appears in a field that uses the Media field type, when trying to upload an image to it.
Image is not loaded and the error appears in the log messages

Steps to reproduce

Add a new field of type media on a content type, and enable the image media type
Add content in the content type and try to upload an image to that field

Proposed resolution

This modification of the code works and the image is uploaded and the textarea for the caption appears

  // Get the entity.
  $field_definition = NULL;
  $form_object = $form_state->getFormObject();
  if ($form_object instanceof EntityFormInterface) {
    $entity = $form_object->getEntity();
    // Get the fields definitions.
    $field_definitions = $entity->getFieldDefinitions();
    // Get the current field definition.
    if (!empty($field_definitions[$element['#field_name']])) {
      $field_definition = $field_definitions[$element['#field_name']];
    }
    elseif (!empty($field_definitions[$element['#field_parents'][0]])) {
      $field_definition = $field_definitions[$element['#field_parents'][0]];
    }
  }

Remaining tasks

Create the patch with the proposed code.

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#6 image_field_caption-3185060-6.patch1.47 KBlucashodge
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

gorkagr created an issue. See original summary.

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

halth’s picture

Status: Active » Needs review

The issue seems to fixed on MR!2. An unused piece of code was removed from _image_field_caption_widget_process().
Please review.

raywalters’s picture

The changes in MR !2 seem to work. Is there a patch for this or will this be merged in?

lucashodge’s picture

StatusFileSize
new1.47 KB

Patch until this is merged.

jimmynash’s picture

Patch in #6 helped with a problem using views bulk operations.

Trying to use VBO and Views Bulk Edit to change the taxonomy terms across a content type that was using image_field_caption resulted in the following error.

Error: Call to undefined method Drupal\views_bulk_operations\Form\ConfigureAction::getEntity() in _image_field_caption_widget_process() (line 49 of /code/web/modules/contrib/image_field_caption/image_field_caption.module)

foxy-vikvik’s picture

Status: Needs review » Reviewed & tested by the community
foxy-vikvik’s picture

Version: 8.x-1.1 » 2.0.x-dev
Assigned: Unassigned » foxy-vikvik

foxy-vikvik’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

It was fixed (commented part of the code on 2.0.x branch) It will be removed soon