elleracompany / craft-cookie-consent

GDPR-Compliant cookie consent banner for Craft CMS
Other
6 stars 5 forks source link

After Craft v4 Upgrade, Can't Access "My Account" with DevMode Enabled #86

Closed curtismorte closed 2 years ago

curtismorte commented 2 years ago

After upgrading to Craft v4, we have consistently been getting the following error when trying to access "My Account" within the Control Panel.

Twig\Error\RuntimeError: Key "heading" for array with keys "cookie-consent:site-settings, cookie-consent:cookie-groups" does not exist. in /app/vendor/craftcms/cms/src/templates/_includes/permissions.twig:77
Stack trace:
#0 /app/vendor/craftcms/cms/src/helpers/Template.php(101): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Array, 'heading', Array, 'any', false, false)
#1 /app/storage/runtime/compiled_templates/77/77e39f84dc589cf9dfb317aaf70f0a78.php(83): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Array, 'heading', Array)
#2 /app/vendor/twig/twig/src/Template.php(394): __TwigTemplate_06be9d2e009c89e2ce4e36ef381b5f37->doDisplay(Array, Array)
#3 /app/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#4 /app/storage/runtime/compiled_templates/08/08b1abd11bba7243987b5738d8c0a49a.php(367): Twig\Template->display(Array)
#5 /app/vendor/twig/twig/src/Template.php(171): __TwigTemplate_69288d26b7e52cdd83e7c5a7ce3d4cb9->block_content(Array, Array)
#6 /app/storage/runtime/compiled_templates/f0/f0df835168c159defb814ce939efc743.php(566): Twig\Template->displayBlock('content', Array, Array)
#7 /app/vendor/twig/twig/src/Template.php(171): __TwigTemplate_e43279df2749f852c2ae540a476ff35e->block_main(Array, Array)
#8 /app/storage/runtime/compiled_templates/f0/f0df835168c159defb814ce939efc743.php(358): Twig\Template->displayBlock('main', Array, Array)
#9 /app/vendor/twig/twig/src/Template.php(171): __TwigTemplate_e43279df2749f852c2ae540a476ff35e->block_body(Array, Array)
#10 /app/storage/runtime/compiled_templates/11/11d935976f7d3c832aa4bee4b8050c1b.php(94): Twig\Template->displayBlock('body', Array, Array)
#11 /app/vendor/twig/twig/src/Template.php(394): __TwigTemplate_7137e3b0f54a9239a011f8ceeb52f8c6->doDisplay(Array, Array)
#12 /app/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#13 /app/storage/runtime/compiled_templates/20/20654a6212e9108321133698db25b169.php(56): Twig\Template->display(Array, Array)
#14 /app/vendor/twig/twig/src/Template.php(394): __TwigTemplate_9453cf14e5aace72eea5739c7a717da1->doDisplay(Array, Array)
#15 /app/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#16 /app/storage/runtime/compiled_templates/f0/f0df835168c159defb814ce939efc743.php(172): Twig\Template->display(Array, Array)
#17 /app/vendor/twig/twig/src/Template.php(394): __TwigTemplate_e43279df2749f852c2ae540a476ff35e->doDisplay(Array, Array)
#18 /app/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#19 /app/storage/runtime/compiled_templates/08/08b1abd11bba7243987b5738d8c0a49a.php(116): Twig\Template->display(Array, Array)
#20 /app/vendor/twig/twig/src/Template.php(394): __TwigTemplate_69288d26b7e52cdd83e7c5a7ce3d4cb9->doDisplay(Array, Array)
#21 /app/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#22 /app/vendor/twig/twig/src/Template.php(379): Twig\Template->display(Array)
#23 /app/vendor/twig/twig/src/TemplateWrapper.php(40): Twig\Template->render(Array, Array)
#24 /app/vendor/twig/twig/src/Environment.php(277): Twig\TemplateWrapper->render(Array)
#25 /app/vendor/craftcms/cms/src/web/View.php(414): Twig\Environment->render('users/_edit', Array)
#26 /app/vendor/craftcms/cms/src/web/View.php(467): craft\web\View->renderTemplate('users/_edit', Array)
#27 /app/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php(52): craft\web\View->renderPageTemplate('users/_edit', Array, 'cp')
#28 /app/vendor/yiisoft/yii2/web/Response.php(1095): craft\web\TemplateResponseFormatter->format(Object(craft\web\Response))
#29 /app/vendor/craftcms/cms/src/web/Response.php(286): yii\web\Response->prepare()
#30 /app/vendor/yiisoft/yii2/web/Response.php(339): craft\web\Response->prepare()
#31 /app/vendor/yiisoft/yii2/base/Application.php(390): yii\web\Response->send()
#32 /app/public/index.php(31): yii\base\Application->run()
#33 {main}

You can find the documentation for Updating Plugins for Craft 4 here. In there, there is a section on how user permissions have changed:

Registering permissions has changed slightly in Craft 4: the RegisterUserPermissionsEvent()’s permissions array now requires individual items with heading and permissions keys


use yii\base\Event;
use craft\events\RegisterUserPermissionsEvent;
use craft\services\UserPermissions;

// Craft 3 Event::on( UserPermissions::class, UserPermissions::EVENT_REGISTER_PERMISSIONS, function(RegisterUserPermissionsEvent $event) { $event->permissions['My Heading'] = $permissions; } );

// Craft 4 Event::on( UserPermissions::class, UserPermissions::EVENT_REGISTER_PERMISSIONS, function(RegisterUserPermissionsEvent $event) { $event->permissions[] = [ 'heading' => 'My Heading', 'permissions' => $permissions, ]; } );

jellingsen commented 2 years ago

Hi, thank you for your detailed issue.

I'll get this fixed.

jellingsen commented 2 years ago

This should now be fixed with v4.0.2.