Views Access to Role issue

Created on 29 April 2021, about 3 years ago
Updated 30 August 2023, 10 months ago

Problem/Motivation

When I want to show view just for specific roles. If user doesn't have that specific role there is following message :

The website encountered an unexpected error. Please try again later.
TypeError: Return value of Drupal\entity_extra_field\Plugin\ExtraFieldType\ExtraFieldViewsPlugin::build() must be of the type array, null returned in Drupal\entity_extra_field\Plugin\ExtraFieldType\ExtraFieldViewsPlugin->build() (line 99 of modules/entity_extra_field/src/Plugin/ExtraFieldType/ExtraFieldViewsPlugin.php).

Steps to reproduce

1.Create new view
2.Use entity extra field to display it on content
3.Everything works fine ,until i update view access :
4.Views > Access > Role permission > Specific role
5.If user has that specific role - no issue, but if user doesn't have he shouldn't be able to see that view, hover following errror message instead :

TypeError: Return value of Drupal\entity_extra_field\Plugin\ExtraFieldType\ExtraFieldViewsPlugin::build() must be of the type array, null returned in Drupal\entity_extra_field\Plugin\ExtraFieldType\ExtraFieldViewsPlugin->build() (line 99 of modules/entity_extra_field/src/Plugin/ExtraFieldType/ExtraFieldViewsPlugin.php).

Drupal\entity_extra_field\Plugin\ExtraFieldType\ExtraFieldViewsPlugin->build(Object, Object) (Line: 305)
Drupal\entity_extra_field\Entity\EntityExtraField->build(Object, Object) (Line: 138)
entity_extra_field_display('view', Array, Object, Object) (Line: 58)
entity_extra_field_entity_view(Array, Object, Object, 'full')
call_user_func_array('entity_extra_field_entity_view', Array) (Line: 403)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_view', Array) (Line: 289)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 239)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725 β†’ ', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
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: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 706)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: duplicate

Version

2.0

Component

Code

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States droath
  • πŸ‡©πŸ‡ͺGermany gngn

    @droath Thank you for commiting the patch from #3344350.
    That solution looks cleaner - but it lacks the change in the annotation:

        *
    -   * @return array|null
    +   * @return array
        *   An renderable array of the view.
        *
    

    Also it would have been nice to be mentioned in the commit ;)

Production build 0.69.0 2024