Problem/Motivation

Previewing the "default" view mode shows PHP notices, e.g.
https://www.example.com/node/2/view-mode/preview/default
shows:

Notice: Undefined index: default in Drupal\view_modes_display\Controller\PreviewController->previewEntity() (line 95 of modules/contrib/view_modes_display/src/Controller/PreviewController.php).

    Notice: Undefined index: default in Drupal\view_modes_display\Controller\PreviewController->previewEntity() (line 95 of modules/contrib/view_modes_display/src/Controller/PreviewController.php).

    Drupal\view_modes_display\Controller\PreviewController->previewEntity(Object, 'node')
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
    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: 158)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

    Notice: Trying to access array offset on value of type null in Drupal\view_modes_display\Controller\PreviewController->previewEntity() (line 95 of modules/contrib/view_modes_display/src/Controller/PreviewController.php).

    Drupal\view_modes_display\Controller\PreviewController->previewEntity(Object, 'node')
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
    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: 158)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

See above

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Anybody created an issue. See original summary.

fathima.asmat’s picture

StatusFileSize
new944 bytes

Patch attached.

fathima.asmat’s picture

Status: Active » Needs review
anybody’s picture

Status: Needs review » Needs work

Thanks @fathima.asmat. Could you please provide this as MR and elaborate (from core perhaps or backtrace) under which conditions

$view_modes[$view_mode]['label']

may not be set?

Does core have similar logics as you wrote?

zach.bimson’s picture

Version: 8.x-2.x-dev » 3.x-dev

Thanks @fathima.asmat for the patch!

@Anybody i think the underlying issue here is that we are fetching a list of all entity view display config but for the preview page we are taking the name of the display and trying to find it in the view modes which are inherently different... going to merge the patch in to the latest dev 3.x to get rid of this warning and explore deeper.

zach.bimson’s picture

Status: Needs work » Fixed
zach.bimson’s picture

Status: Fixed » Closed (fixed)

Released in `3.0.0`