When uninstalling my module with a custom entity I receive the following error:

Notice: Undefined index: image_moderate in dynamic_entity_reference_entity_bundle_delete() (line 39 of modules/contrib/dynamic_entity_reference/dynamic_entity_reference.module).

dynamic_entity_reference_entity_bundle_delete('image_moderate', 'image_moderate')
call_user_func_array('dynamic_entity_reference_entity_bundle_delete', Array) (Line: 402)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_bundle_delete', Array) (Line: 84)
Drupal\Core\Entity\EntityBundleListener->onBundleDelete('image_moderate', 'image_moderate') (Line: 625)
Drupal\Core\Entity\EntityManager->onBundleDelete('image_moderate', 'image_moderate') (Line: 389)
Drupal\Core\Extension\ModuleInstaller->uninstall(Array, 1) (Line: 91)
Drupal\Core\ProxyClass\Extension\ModuleInstaller->uninstall(Array) (Line: 160)
Drupal\system\Form\ModulesUninstallConfirmForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 585)
Drupal\Core\Form\FormBuilder->processForm('system_modules_uninstall_confirm_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('system_modules_uninstall_confirm_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}()
call_user_func_array(Object, Array) (Line: 153)
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: 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: 657)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

But I do not use Dynamic Entity Reference for this module / entity.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

slowflyer created an issue. See original summary.

jibran’s picture

Status: Active » Needs review
FileSize
546 bytes

Thanks for creating the issue. Can you please try this patch?

jibran’s picture

Version: 8.x-1.4 » 8.x-1.x-dev

Status: Needs review » Needs work

The last submitted patch, 2: 2938075-2.patch, failed testing. View results

jibran’s picture

Status: Needs work » Needs review

Ignore 2.x fails. HEAD is failing.

Sam152’s picture

Is $ids really empty in the buggy code path? It enters for foreach which implies there are some values to me. The issue as I'm reading it is, there are no handler settings inside the loaded field for that entity type. If we're already checking if the handler settings exist, simply shuffling this around should work too, no?

diff --git a/dynamic_entity_reference.module b/dynamic_entity_reference.module
index cdb7251..d6fe4ed 100644
--- a/dynamic_entity_reference.module
+++ b/dynamic_entity_reference.module
@@ -36,8 +36,8 @@ function dynamic_entity_reference_entity_bundle_delete($entity_type_id, $bundle)
     $settings = $field_config->getSettings();
     $target_types = DynamicEntityReferenceItem::getTargetTypes($settings);
     if (in_array($entity_type_id, $target_types, TRUE)) {
-      $handler_settings = $settings[$entity_type_id]['handler_settings'];
-      if (isset($handler_settings['target_bundles'][$bundle])) {
+      if (isset($settings[$entity_type_id]['handler_settings']['target_bundles'][$bundle])) {
+        $handler_settings = $settings[$entity_type_id]['handler_settings'];
         unset($handler_settings['target_bundles'][$bundle]);
         $settings[$entity_type_id]['handler_settings'] = $handler_settings;
         $field_config->setSettings($settings);
jibran’s picture

FileSize
676 bytes

Nice catch! I always confuse NULL with an empty array with these loadMultiple. I totally misread the logic and backtrace. Here is the updated patch.

Status: Needs review » Needs work

The last submitted patch, 7: 2914503-8.patch, failed testing. View results

jibran’s picture

acbramley’s picture

Status: Needs review » Reviewed & tested by the community

LGTM!

  • jibran committed e22fa5a on 8.x-1.x
    Issue #2938075 by jibran, slowflyer, Sam152, acbramley: Error on...

  • jibran committed 854c37c on 8.x-2.x
    Issue #2938075 by jibran, slowflyer, Sam152, acbramley: Error on...
jibran’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, for the review c/p to 1.x and 2.x.

Status: Fixed » Closed (fixed)

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