I went to create a new media type and got the following error:

The website encountered an unexpected error. Please try again later.
Error: Call to a member function id() on null in media_expire_form_media_type_form_alter() (line 25 of modules/contrib/media_expire/media_expire.module).

media_expire_form_media_type_form_alter(Array, Object, 'media_type_add_form') (Line: 539)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'media_type_add_form') (Line: 830)
Drupal\Core\Form\FormBuilder->prepareForm('media_type_add_form', Array, Object) (Line: 272)
Drupal\Core\Form\FormBuilder->buildForm('media_type_add_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 100)
Drupal\cleanpager\StackMiddleware\CleanPager->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 664)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Suggestions?

Comments

Christopher Riley created an issue. See original summary.

anu17’s picture

When I had enabled media expire module, was facing an error on adding of new media type.
I have attached a patch solving the same issue.

anu17’s picture

Status: Active » Needs review
anu17’s picture

riddhi.addweb’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new95.25 KB
new11.38 KB
new346.97 KB

@anu17, Thanks for solving this error, your patch is working fine for me. I checked it using simplytest.me & attached the screenshot for the same.

namit.garg’s picture

Patch works as expected

chr.fritsch’s picture

Version: 8.x-2.0-alpha4 » 8.x-2.x-dev
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.22 KB

We could do something smarter and just call the logic on the edit form. Then the object is always there.

  • chr.fritsch committed 9e2d2b8 on 8.x-2.x
    Issue #2973699 by anu17, chr.fritsch, riddhi.addweb: Error when trying...
chr.fritsch’s picture

Status: Needs review » Fixed

Fixed, thanks everyone

Status: Fixed » Closed (fixed)

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