Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
On /media/add/document page can not create Document type media because it causes an error:
Fatal error: Call to a member function isEmpty() on a non-object in /modules/contrib/media_entity_document/src/Plugin/MediaEntity/Type/Document.php on line 46
It happens because Mime type and Size fields of the Document are hidden on /admin/structure/media/manage/document/form-display page
Comments
Comment #2
fox mulder CreditAttribution: fox mulder commentedhmmm, it's intresting. First of all:
1. I can not reproduce this on simplytest.me
2. I think so, it's a media_entity_document related issue
There is another symptom / the real source of the fatal error:
on /admin/structure/media/manage/document the Type provider configuration fieldset is empty and because of this in /media_entity_document/src/Plugin/MediaEntity/Type/Document.php -> getField() function the $this->configuration is empty and $media->{$source_field}->entity does not exist ( this causes the fatal error )
I used a workaround:
1. I added buildConfigurationForm() function into /modules/contrib/media_entity_document/src/Plugin/MediaEntity/Type/Document.php ( see patch contents below )
2. I saved the /admin/structure/media/manage/document form
3. Now the fatal error terminates and all things work good ( I can create Document type media entities )
4. I removed the buildConfigurationForm() from /modules/contrib/media_entity_document/src/Plugin/MediaEntity/Type/Document.php
Patch:
Anybody can reproduce this?