diff --git a/CHANGELOG.md b/CHANGELOG.md index a69915132a0..91a30bba073 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft CMS 5 +## Unreleased + +- Fixed an error that could occur when creating an entry via a slideout, if the slideout was submitted before the entry was autosaved. ([#15134](https://github.com/craftcms/cms/pull/15134)) + ## 5.1.8 - 2024-06-03 - Added `craft\helpers\Gql::isIntrospectionQuery()`. diff --git a/src/controllers/ElementsController.php b/src/controllers/ElementsController.php index 6a5f5c9128f..512564f6deb 100644 --- a/src/controllers/ElementsController.php +++ b/src/controllers/ElementsController.php @@ -1634,9 +1634,14 @@ public function actionApplyDraft(): ?Response $this->requirePostRequest(); $elementsService = Craft::$app->getElements(); - /** @var Element|DraftBehavior|null $element */ + /** @var Element|DraftBehavior|Response|null $element */ $element = $this->_element(); + // this can happen if creating element via slideout, and we hit "create entry" before the autosave kicks in + if ($element instanceof Response) { + return $element; + } + if (!$element || !$element->getIsDraft()) { throw new BadRequestHttpException('No draft was identified by the request.'); }