Skip to content

[5.x]: "User not authorized to create this element." after cancelling the creation of a block on matrix field #15015

@brionwolf

Description

@brionwolf

What happened?

Description

  • Clicking away or clicking "cancel" while creating an entry in a drawer for a matrix field works as expected (cancelling the creation of that block), but clicking the "add block" button again will throw a "User not authorized to create this element." error.

Steps to reproduce

  1. Create a matrix field, with at least one entry type.
  2. Set a Max Entries value (ie: 1 or 2).
  3. Set the view mode to "As an element index" or "As cards"
  4. Add the matrix field to another field layout for testing.
  5. Create or edit an entry with the matrix field.
  6. Click the button to add a new block to the matrix field
  7. Once the entry create drawer opens, cancel the creation of the entry.
  8. Repeat steps 6 and 7 until you have done so once-more than the "Max Entries" value.

Expected behavior

  • I should be able to cancel and/or add a block from the matrix field as many times as I want.

Actual behavior

  • Craft throws an error stating "User not authorized to create this element.", and the element cannot be recreated.
  • If the Max Entries value is greater than 1, one of the "canceled" entries may appear as a draft entry after reloading the page, or attempting to save.
  • If the matrix block is nested in the field layout of another matrix block I occasionally have to delete and create the parent block to resolve the error.

Screen captures:

animated image of a craft control panel reproducing an example of the error

Stack Trace:

yii\web\ForbiddenHttpException: User not authorized to create this element. in craft/vendor/craftcms/cms/src/controllers/ElementsController.php:2186
Stack trace:
#0 craft/vendor/craftcms/cms/src/controllers/ElementsController.php(194): craft\controllers\ElementsController->_createElement()
#1 [internal function]: craft\controllers\ElementsController->actionCreate()
#2 craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#3 craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#4 craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('create', Array)
#5 craft/vendor/craftcms/cms/src/web/Application.php(349): yii\base\Module->runAction('elements/create', Array)
#6 craft/vendor/craftcms/cms/src/web/Application.php(650): craft\web\Application->runAction('elements/create', Array)
#7 craft/vendor/craftcms/cms/src/web/Application.php(311): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#8 craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#9 craft/web/index.php(12): yii\base\Application->run()
#10 {main}

Craft CMS version

Craft Pro 5.1.3

PHP version

8.3.4

Operating system and version

MacOS Sonoma 14.4.1 (23E224)

Database type and version

MySQL 8.3.0

Image driver and version

GD 8.3.4

Installed plugins and versions

  • CKEditor | 4.0.5

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions