Problem/Motivation

First, thanks for this module that is very useful. The problem comes when I want to use Dashboards with Layout Builder on the same site.

Steps to reproduce

As soon as I create a dashboard, I'm getting the following error message:

Error: Call to undefined method Drupal\dashboards\Entity\Dashboard::hasField() in paragraph_view_mode_entity_view_mode_alter() (line 41 of .../web/modules/contrib/paragraph_view_mode/paragraph_view_mode.module)

Proposed resolution

Not sure where to look for to solve this. I had posted an issue few days ago on the Dashboards module side (https://www.drupal.org/project/dashboards/issues/3159965) but no feedback yet.

Thanks for any help.

Comments

sahaj created an issue. See original summary.

dan_metille’s picture

Here is the remaining part of the above error message:

#0 .../web/core/lib/Drupal/Core/Extension/ModuleHandler.php(539): paragraph_view_mode_entity_view_mode_alter('full', Object(Drupal\dashboards\Entity\Dashboard), Array)
#1 .../web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(191): Drupal\Core\Extension\ModuleHandler->alter('entity_view_mod...', 'full', Object(Drupal\dashboards\Entity\Dashboard), Array)
#2 .../web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(168): Drupal\Core\Entity\EntityViewBuilder->getBuildDefaults(Object(Drupal\dashboards\Entity\Dashboard), 'full')
#3 .../web/modules/contrib/dashboards/src/Entity/DashboardViewBuilder.php(119): Drupal\Core\Entity\EntityViewBuilder->viewMultiple(Array, 'full', NULL)
#4 .../web/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php(105): Drupal\dashboards\Entity\DashboardViewBuilder->view(Object(Drupal\dashboards\Entity\Dashboard), 'full')
#5 [internal function]: Drupal\Core\Entity\Controller\EntityViewController->view(Object(Drupal\dashboards\Entity\Dashboard), 'full')
#6 .../web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#7 .../web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#8 .../web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#9 .../web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#10 .../vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#11 .../vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#12 .../web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#13 .../web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 .../web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 .../web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 .../web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 .../web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 .../vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 .../web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 .../web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#21 {main}

  • sayco committed 5c1fbbf on 8.x-1.x
    Issue #3161692 by sahaj, sayco: Issue when using in conjonction with...
sayco’s picture

Hi @sahaj, thank you for reporting the issue! This seems like a critical issue in the module. I haven't considered the entities that are not fieldable. Anyway, the best option was to check if the given entity in hook_entity_view_mode_alter is an instance of ParagraphInterface as this is the only entity type interface we are interested in. I've already committed the changes to dev branch, soon I will release a new version, as this issue seems to be very crucial.

sayco’s picture

Status: Active » Fixed
dan_metille’s picture

@sayco very quick! I can confirm that this is fixed for me. Big thanks!

Status: Fixed » Closed (fixed)

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