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}| Comment | File | Size | Author |
|---|---|---|---|
| #6 | form_mode_control-string_permission-3409223-6.patch | 1.49 KB | liam morland |
| #4 | form_mode_control-string_permission-3409223-4.patch | 1.07 KB | liam morland |
Issue fork form_mode_control-3409223
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
Comment #2
duckydan commentedAdditional 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.
Comment #4
liam morlandI 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 fromform_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.
Comment #5
andypostThe issue is that
form_mode_control_get_permission_by_mode_and_role()may returnNULLinstead of stringNice fix
Comment #6
liam morlandA better fix. Only the last hunk is actually needed, but the other part is an improvement.
Comment #7
liam morlandComment #8
duckydan commentedFixed it perfectly!
Thanks!
Comment #9
duckydan commentedComment #10
bakopHi, tested on Drupal 10.2.1 ! RTBC +1
Comment #11
dcam commented#6 fixed the problem for us too.
Comment #12
turbogeek commented#6 fixed the issue. Thanks!
Comment #13
sboden commented#6 fixes the issue on a Drupal 10.2.2
Comment #14
pgn5qs commentedIs this ever going to be updated in a new release of the module? This is preventing core upgrades with a site breaking bug.
Comment #15
quadrexdevTested it on my project and it worked well, Drupal 10.2 +1 to RTBC
Comment #17
mandclu commentedThanks @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.