Once I upgraded a site to 10.2, I starte3d getting an error I have tracked down to this module.

This happens:

TypeError: Drupal\Core\Session\PermissionChecker::hasPermission(): Argument #1 ($permission) must be of type string, null given, called in /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/Session/UserSession.php on line 123 in Drupal\Core\Session\PermissionChecker->hasPermission() (line 23 of /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/Session/PermissionChecker.php).

Once I uninstalled form_mode_control it stopped.

Backtrace:

#0 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/Session/UserSession.php(123): Drupal\Core\Session\PermissionChecker->hasPermission()
#1 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/Session/AccountProxy.php(121): Drupal\Core\Session\UserSession->hasPermission()
#2 /var/www/html/beta.weavercafe/web/modules/contrib/form_mode_control/form_mode_control.module(212): Drupal\Core\Session\AccountProxy->hasPermission()
#3 /var/www/html/beta.weavercafe/web/modules/contrib/form_mode_control/form_mode_control.module(40): form_mode_control_control_access_form_mode()
#4 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(545): form_mode_control_entity_form_display_alter()
#5 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php(133): Drupal\Core\Extension\ModuleHandler->alter()
#6 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/Entity/ContentEntityForm.php(284): Drupal\Core\Entity\Entity\EntityFormDisplay::collectRenderDisplay()
#7 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/Entity/EntityForm.php(97): Drupal\Core\Entity\ContentEntityForm->init()
#8 [internal function]: Drupal\Core\Entity\EntityForm->buildForm()
#9 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/Form/FormBuilder.php(536): call_user_func_array()
#10 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/Form/FormBuilder.php(283): Drupal\Core\Form\FormBuilder->retrieveForm()
#11 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
#12 [internal function]: Drupal\Core\Controller\FormController->getContentResult()
#13 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#14 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#15 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#16 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#17 /var/www/html/beta.weavercafe/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#18 /var/www/html/beta.weavercafe/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#19 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#20 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#21 /var/www/html/beta.weavercafe/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#22 /var/www/html/beta.weavercafe/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#23 /var/www/html/beta.weavercafe/web/modules/contrib/shield/src/ShieldMiddleware.php(270): Drupal\page_cache\StackMiddleware\PageCache->handle()
#24 /var/www/html/beta.weavercafe/web/modules/contrib/shield/src/ShieldMiddleware.php(226): Drupal\shield\ShieldMiddleware->bypass()
#25 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\shield\ShieldMiddleware->handle()
#26 /var/www/html/beta.weavercafe/web/modules/contrib/cloudflare/src/CloudFlareMiddleware.php(136): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#27 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\cloudflare\CloudFlareMiddleware->handle()
#28 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#29 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#30 /var/www/html/beta.weavercafe/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#31 /var/www/html/beta.weavercafe/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#32 {main}
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

duckydan created an issue. See original summary.

duckydan’s picture

Additional info: It still works for user 1. It seems to be regular users that see the issue when going to a link that has a form where there exists a form mode controlled by form_mode_control. Even if that user is trying to look at the default form mode.

Liam Morland made their first commit to this issue’s fork.

liam morland’s picture

Version: 8.x-2.1 » 8.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new1.07 KB

I have seen this too. The problem is that in Drupal 10.2, the permission passed to UserSession::hasPermission() must be a string. It previously did not enforce this. The permission passed there comes from form_mode_control_get_permission_by_mode_and_role(), so that must always return a string instead of sometimes returning NULL. Fix attached and in the issue fork.

I put the change on the issue fork, but I do not see any way to make a merge request.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

The issue is that form_mode_control_get_permission_by_mode_and_role() may return NULL instead of string

Nice fix

liam morland’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.49 KB

A better fix. Only the last hunk is actually needed, but the other part is an improvement.

liam morland’s picture

Title: Error on 10.2 » Pass only strings to UserSession::hasPermission()
Issue tags: +Drupal 10.2 compatibility
duckydan’s picture

Fixed it perfectly!

Thanks!

duckydan’s picture

Status: Needs review » Reviewed & tested by the community
bakop’s picture

Hi, tested on Drupal 10.2.1 ! RTBC +1

dcam’s picture

#6 fixed the problem for us too.

turbogeek’s picture

#6 fixed the issue. Thanks!

sboden’s picture

#6 fixes the issue on a Drupal 10.2.2

pgn5qs’s picture

Is this ever going to be updated in a new release of the module? This is preventing core upgrades with a site breaking bug.

quadrexdev’s picture

Tested it on my project and it worked well, Drupal 10.2 +1 to RTBC

  • mandclu committed edc19250 on 8.x-2.x
    Issue #3409223 by Liam Morland: Pass only strings to UserSession::...
mandclu’s picture

Status: Reviewed & tested by the community » Fixed

Thanks @Liam Morland for the fix, and also thanks to everyone who provided input on this. The change has been merged in, and I will roll a new release shortly.

Status: Fixed » Closed (fixed)

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