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
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | image_field_caption-3185060-6.patch | 1.47 KB | lucashodge |
Issue fork image_field_caption-3185060
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
Comment #4
halthThe issue seems to fixed on MR!2. An unused piece of code was removed from _image_field_caption_widget_process().
Please review.
Comment #5
raywalters commentedThe changes in MR !2 seem to work. Is there a patch for this or will this be merged in?
Comment #6
lucashodge commentedPatch until this is merged.
Comment #7
jimmynash commentedPatch 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)Comment #8
foxy-vikvik commentedComment #9
foxy-vikvik commentedComment #12
foxy-vikvik commentedIt was fixed (commented part of the code on 2.0.x branch) It will be removed soon