craft-calendar icon indicating copy to clipboard operation
craft-calendar copied to clipboard

User not authorized to create this element when inserting a content type with Craft matrix field and multisite

Open theWiseCat opened this issue 8 months ago • 6 comments

What happened?

In my CraftCMS + Calendar setup, I have set up two sites in the same group, one for each local for my website (French and English). I use a Matrix field as a pagebuilder with the propagation method "Save entries on other sites of the same group".

When I create a new event, I can only add entries in the pagebuilder in the French site and I get the user not authorized error when I try to add an entry in the English site for the same event. I don't get this issue in my regular Craft entries, only in Calendar events.

All of this is happening as I am logged in as an admin user with every permissions available.

Errors and Stack Trace (if available)

[web.ERROR] [yii\web\HttpException:403] yii\web\ForbiddenHttpException: User not authorized to create this element. in /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php:2513
Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php(214): craft\controllers\ElementsController->_createElement()
#1 [internal function]: craft\controllers\ElementsController->actionCreate()
#2 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#3 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#4 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#5 /var/www/html/vendor/craftcms/cms/src/web/Application.php(361): yii\base\Module->runAction()
#6 /var/www/html/vendor/craftcms/cms/src/web/Application.php(660): craft\web\Application->runAction()
#7 /var/www/html/vendor/craftcms/cms/src/web/Application.php(323): craft\web\Application->_processActionRequest()
#8 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest()
#9 /var/www/html/web/index.php(12): yii\base\Application->run()
#10 {main} {"memory":10620040,"exception":"[object] (yii\\web\\ForbiddenHttpException(code: 0): User not authorized to create this element. at /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php:2513)"}

How can we reproduce this?

  1. In Calendar > Events : Create a new Calendar event in French.
  2. Fill every required fields and save the entry.
  3. Create an entry in the pagebuilder Matrix field, still in the French event : notice that the creation of a new entry with the Matrix field works.
  4. Switch to the English event with the site selector in the breadcrumbs.
  5. Notice that the entry did not propagate to the pagebuilder Matrix field in English.
  6. Create an entry in the pagebuilder Matrix field in the English event : get the User not authorized error.

I also get the issue if creating the event in English first :

  1. In Calendar > Events : Create a new Calendar event in English.
  2. Fill every required fields and save the entry.
  3. Create an entry in the pagebuilder Matrix field, still in the English event : get the User not authorized error.

Calendar Edition

Pro

Calendar Version

5.0.16

Craft Version

5.6.17

When did this issue start?

  • [ ] Unsure
  • [x] Fresh install of Calendar
  • [ ] After upgrading from older Calendar version
  • [ ] After upgrading from older Craft version
  • [ ] After a change to hosting configuration

Previous Calendar Version

No response

theWiseCat avatar Apr 16 '25 16:04 theWiseCat

@theWiseCat

Can I see your Matrix field setup so I can replicate it please.

seandelaney avatar May 07 '25 14:05 seandelaney

Hi @seandelaney

Here's my matrix field "Pagebuilder" config. I removed some of the entryTypes in the config to make it shorter and easier to read.

columnSuffix: null
handle: pagebuilder
instructions: null
name: Pagebuilder
searchable: false
settings:
  createButtonLabel: 'Nouveau bloc'
  defaultIndexViewMode: cards
  enableVersioning: false
  entryTypes:
    -
      __assoc__:
        -
          - uid
          - 9c9bee19-94cb-43b7-8930-cd448db85533 # Bloc texte-image
    -
      __assoc__:
        -
          - uid
          - 9c68f318-e451-4da3-9545-728727997380 # Bloc média
  includeTableView: false
  maxEntries: null
  minEntries: null
  pageSize: 50
  propagationKeyFormat: null
  propagationMethod: siteGroup
  showCardsInGrid: false
  viewMode: cards
translationKeyFormat: null
translationMethod: site
type: craft\fields\Matrix

I noticed the issue can be worked around by changing the viewMode from "cards" to "blocks" (Inline fields). It is not ideal as my entryTypes have a lot of fields and it makes entering content harder.

I also have a similar issue with entryTypes in a CKEditor field. It works in the first site (french) but not in the second (english). Both issues seems related to the ownership of the elements. Here's the message and stack trace for this error :

[web.ERROR] [TypeError] TypeError: craft\services\Elements::canSave(): Argument #1 ($element) must be of type craft\base\ElementInterface, null given, called in /var/www/html/vendor/craftcms/ckeditor/src/Field.php on line 579 and defined in /var/www/html/vendor/craftcms/cms/src/services/Elements.php:4463
Stack trace:
#0 /var/www/html/vendor/craftcms/ckeditor/src/Field.php(579): craft\services\Elements->canSave()
#1 /var/www/html/vendor/craftcms/cms/src/base/Element.php(3636): craft\ckeditor\Field->canSaveElement()
#2 /var/www/html/vendor/craftcms/cms/src/elements/Entry.php(1898): craft\base\Element->canSave()
#3 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(4472): craft\elements\Entry->canSave()
#4 /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php(2665): craft\services\Elements->canSave()
#5 /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php(221): craft\controllers\ElementsController->_createElement()
#6 [internal function]: craft\controllers\ElementsController->actionCreate()
#7 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#8 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#9 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#10 /var/www/html/vendor/craftcms/cms/src/web/Application.php(361): yii\base\Module->runAction()
#11 /var/www/html/vendor/craftcms/cms/src/web/Application.php(660): craft\web\Application->runAction()
#12 /var/www/html/vendor/craftcms/cms/src/web/Application.php(323): craft\web\Application->_processActionRequest()
#13 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest()
#14 /var/www/html/web/index.php(12): yii\base\Application->run()
#15 {main} {"memory":14597816,"exception":"[object] (TypeError(code: 0): craft\\services\\Elements::canSave(): Argument #1 ($element) must be of type craft\\base\\ElementInterface, null given, called in /var/www/html/vendor/craftcms/ckeditor/src/Field.php on line 579 at /var/www/html/vendor/craftcms/cms/src/services/Elements.php:4463)"}

theWiseCat avatar May 08 '25 14:05 theWiseCat

Sorry about this @theWiseCat.

This is the same issue and limitation we have noted here: https://github.com/solspace/craft-calendar/issues/379#issuecomment-2807996274

We have plans to make large updates to Calendar to resolve these quirks in the not-too-distant future. 🙂

kjmartens avatar May 09 '25 04:05 kjmartens

Thank you for your help, I will use the inline fields in the meantime.

Do you have an estimate around when will this be resolved?

theWiseCat avatar May 09 '25 18:05 theWiseCat

@theWiseCat it could be a couple of months, unfortunately.

kjmartens avatar May 09 '25 19:05 kjmartens

I have the same issue, and I don't have a workaround for a specific item. Can we expect a fix soon? Thank you.

GaelPQCQ avatar Nov 13 '25 16:11 GaelPQCQ