Skip to content

[5.x]: Attempting to save an element in an unsupported site when creating new nested entry for non primary site #16158

@dolphiq-allard

Description

@dolphiq-allard

What happened?

Description

Craft 5.5.2 throws an error (Attempting to save an element in an unsupported site) when trying to add an entry in a CKEditor field.

In a multi-lingual site I can add entries within the CKEditor field in the main language, however, in the secondary language, an error is thrown and the entry is not added to the CKEditor field. This error was introduced somewhere between version 5.1.x and 5.5.x. I've added multiple entries within the CKEditor field before upgrading to the latest version.

Error from log files:

Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1308): craft\services\Elements->_saveElementInternal()
#1 /var/www/html/vendor/craftcms/cms/src/services/Drafts.php(261): craft\services\Elements->saveElement()
#2 /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php(212): craft\services\Drafts->saveElementAsDraft()
#3 [internal function]: craft\controllers\ElementsController->actionCreate()
#4 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#5 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#6 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#7 /var/www/html/vendor/craftcms/cms/src/web/Application.php(350): yii\base\Module->runAction()
#8 /var/www/html/vendor/craftcms/cms/src/web/Application.php(649): craft\web\Application->runAction()
#9 /var/www/html/vendor/craftcms/cms/src/web/Application.php(312): craft\web\Application->_processActionRequest()
#10 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest()
#11 /var/www/html/web/index.php(12): yii\base\Application->run()
#12 {main} {"memory":2052936,"exception":"[object] (craft\\errors\\UnsupportedSiteException(code: 0): Attempting to save an element in an unsupported site. at /var/www/html/vendor/craftcms/cms/src/services/Elements.php:3531)"} 

This error is thrown both on production and on the development environment (DDEV)

Steps to reproduce

  1. In the secondary language version of a content page, try to add an entry to the CKEditor field

Expected behavior

The entry is added to the CKEditor field, and can be edited by double clicking it.

Actual behavior

A toast stating A server error occurred. appears and nothing else happens. The error above is logged in the logfiles.

Craft CMS version

5.5.2

PHP version

8.3.13

Operating system and version

Linux 5.10.0-32-amd64

Database type and version

MariaDB 10.6.20

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions