diff -u b/panels_ipe/src/TempStoreTrait.php b/panels_ipe/src/TempStoreTrait.php --- b/panels_ipe/src/TempStoreTrait.php +++ b/panels_ipe/src/TempStoreTrait.php @@ -2,6 +2,7 @@ namespace Drupal\panels_ipe; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant; /** @@ -10,13 +11,6 @@ trait TempStoreTrait { /** - * The module handler. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** * Returns the tempstore ID of a Panels IPE display. * * Modules will be allowed to alter the ID via @@ -34,9 +28,17 @@ protected function getTempStoreId(PanelsDisplayVariant $panels_display) { $id = $panels_display->id(); - // Allow modules to determine the tempstore ID. - $module_handler = $this->moduleHandler ?: \Drupal::moduleHandler(); + // Get the module handler. We cannot define a $moduleHandler property in + // this trait, or we could get fatal errors if classes that use this trait + // have a $moduleHandler property of their own. + if (isset($this->moduleHandler) && $this->moduleHandler instanceof ModuleHandlerInterface) { + $module_handler = $this->moduleHandler; + } + else { + $module_handler = \Drupal::moduleHandler(); + } + // Allow modules to alter the tempstore ID. $module_handler ->alter('panels_ipe_tempstore_id', $id, $panels_display);