Call to a member function getViewMode() on null in Drupal\eca_content\HookHandler->viewModeAlter()

Created on 22 January 2025, 7 days ago

Problem/Motivation

On viewing a piece of content:

Error: Call to a member function getViewMode() on null in Drupal\eca_content\HookHandler->viewModeAlter() (line 333 of modules/contrib/eca/modules/content/src/HookHandler.php).

eca_content_entity_view_mode_alter('full', Object, NULL) (Line: 552)
Drupal\Core\Extension\ModuleHandler->alter('node_view_mode', 'full', Object) (Line: 180)
Drupal\Core\Entity\EntityViewBuilder->getBuildDefaults(Object, 'full') (Line: 61)
Drupal\node\NodeViewBuilder->getBuildDefaults(Object, 'full') (Line: 157)
Drupal\Core\Entity\EntityViewBuilder->viewMultiple(Array, 'full', NULL) (Line: 123)
Drupal\Core\Entity\EntityViewBuilder->view(Object, 'full') (Line: 134)
Drupal\Core\Entity\Controller\EntityViewController->view(Object, 'full') (Line: 66)
Drupal\node\Controller\NodeViewController->view(Object, 'full', NULL)

Steps to reproduce

Not sure. Enable and have a module that uses ECA Content, anyhow.

Proposed resolution

Probably like #3325480: ECA Render: Call to a member function getMode() on null in eca_render_form_alter() โ†’ this is really a bug elsewhere, but it would be really good of ECA to avoid fatal errors if it canโ€” "adding a safety net in our code doesn't harm."

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States mlncn Minneapolis, MN, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mlncn
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mlncn Minneapolis, MN, USA

    This is pretty weird thoughโ€” adding an explicit 'full' view mode to the content type in question did not help, did not expect it to, but there are no models configured that have anything to do with eca.content_entity.view_mode_alter.

    Could i have an unconfigured event that's firing for all possible events somehow?

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jurgenhaas Gottmadingen

    This is long before an ECA model comes into play. When this code gets executed, this is when Drupal core calls the hook_entity_view_mode_alter(). ECA is dispatching an event for that hook, so that models could subscribe to that event.

    The stack trace above means, that the following code in \Drupal\eca_content\HookHandler::viewModeAlter can not dispatch the required event:

          $event = $this->triggerEvent->dispatchFromPlugin('content_entity:viewmodealter', $entity, $this->entityTypes, $view_mode);
    

    That's then returning $event = NULL and that's then causing the exception.

    Now, it's strange that your Drupal installation can not dispatch that event, as it is always dispatched everywhere and we've never seen that error before.

    The problem is in \Drupal\eca\Event\TriggerEvent::dispatchFromPlugin and you should go there with either xdebug or with some extra logging core in the try/catch scenario to find out what's exactly happening there. You could e.g. replace the catch part with the following code to get an extra output in your Drupal logs:

        catch (PluginException $ex) {
          \Drupal\Core\Utility\Error::logException(\Drupal::logger('ECA Debug'), $ex);
          return NULL;
        }
    
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jurgenhaas Gottmadingen
Production build 0.71.5 2024