From 7f066a7443a4d8ebae5d4f2c7c3f35a4443d6c00 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Tue, 24 Sep 2024 11:29:17 +0200 Subject: [PATCH] Fix errors after save a new page --- docs/CHANGELOG.md | 4 ++++ models/CustomContentContainer.php | 4 ++-- models/MarkdownType.php | 6 +++++- models/TemplateType.php | 8 ++++++-- module.json | 2 +- modules/template/models/ContainerContent.php | 17 ++++++++--------- .../models/ContainerContentDefinition.php | 4 ++-- 7 files changed, 28 insertions(+), 17 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 460ad725..481f9bcf 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +1.10.8 (Unreleased) +---------------------------- +- Fix #347: Fix errors after save a new page + 1.10.7 (September 19, 2024) ---------------------------- - Enh #342: JS Dependency Updates diff --git a/models/CustomContentContainer.php b/models/CustomContentContainer.php index 9ad410ba..8da3c130 100644 --- a/models/CustomContentContainer.php +++ b/models/CustomContentContainer.php @@ -519,6 +519,8 @@ protected function checkAbstract() */ public function afterSave($insert, $changedAttributes) { + parent::afterSave($insert, $changedAttributes); + if (!$this->getContentType()->afterSave($this, $insert, $changedAttributes)) { throw new LogicException('Could not save content type' . $this->getContentType()->getLabel()); } @@ -526,8 +528,6 @@ public function afterSave($insert, $changedAttributes) if ($this->checkAbstract()) { RichText::postProcess($this->abstract, $this); } - - parent::afterSave($insert, $changedAttributes); } /** diff --git a/models/MarkdownType.php b/models/MarkdownType.php index 399b9810..865890e4 100644 --- a/models/MarkdownType.php +++ b/models/MarkdownType.php @@ -34,6 +34,10 @@ function getId() */ public function afterSave($page, $insert, $changedAttributes) { + if (!parent::afterSave($page, $insert, $changedAttributes)) { + return false; + } + RichText::postProcess($page->page_content, $page); return true; } @@ -62,4 +66,4 @@ public function renderFormField(ActiveForm $form, CustomContentContainer $page) { return $form->field($page, $page->getPageContentProperty())->widget(RichTextField::class, [ 'pluginOptions' => ['maxHeight' => '500px']]); } -} \ No newline at end of file +} diff --git a/models/TemplateType.php b/models/TemplateType.php index c6260520..f0a1bbdf 100644 --- a/models/TemplateType.php +++ b/models/TemplateType.php @@ -44,7 +44,11 @@ function getDescription() */ public function afterSave($page, $insert, $changedAttributes) { - if($insert) { + if (!parent::afterSave($page, $insert, $changedAttributes)) { + return false; + } + + if ($insert) { $templateInstance = new TemplateInstance([ 'object_model' => get_class($page), 'object_id' => $page->id, @@ -104,4 +108,4 @@ public function renderFormField(ActiveForm $form, CustomContentContainer $page) { return $form->field($page, 'templateId')->dropDownList($page->getAllowedTemplateSelection(), ['value' => $page->getTemplateId(), 'disabled' => !$page->isNewRecord]); } -} \ No newline at end of file +} diff --git a/module.json b/module.json index 765b2d73..8645c7f2 100644 --- a/module.json +++ b/module.json @@ -3,7 +3,7 @@ "name": "Custom Pages", "description": "Create custom pages and widgets and share them with your users. Take advantage of a wide range of editing options, including HTML and Markdown.", "keywords": ["pages", "custom", "iframe", "markdown", "link", "navigation", "spaces"], - "version": "1.10.7", + "version": "1.10.8", "homepage": "https://github.com/humhub/custom-pages", "humhub": { "minVersion": "1.14" diff --git a/modules/template/models/ContainerContent.php b/modules/template/models/ContainerContent.php index 08d36b45..b429b348 100644 --- a/modules/template/models/ContainerContent.php +++ b/modules/template/models/ContainerContent.php @@ -13,7 +13,6 @@ */ class ContainerContent extends TemplateContentActiveRecord { - public static $label = 'Container'; /** @@ -47,6 +46,8 @@ public function getAllowedTemplates() public function afterSave($insert, $changedAttributes) { + parent::afterSave($insert, $changedAttributes); + if (!empty($this->allowedTemplateSelection)) { ContainerContentTemplate::deleteAll(['container_content_id' => $this->id]); foreach ($this->allowedTemplateSelection as $allowedTemplateId) { @@ -56,8 +57,6 @@ public function afterSave($insert, $changedAttributes) $allowedTemplate->save(); } } - - parent::afterSave($insert, $changedAttributes); } public function beforeDelete() @@ -112,8 +111,8 @@ public function renderEmpty($options = []) $options['jsWidget'] = 'custom_pages.template.TemplateContainer'; return $this->renderEmptyDiv(Yii::t('CustomPagesModule.models_Container', 'Empty
Container'), $options, [ 'class' => 'emptyContainerBlock', - 'data-template-multiple' => $this->definition->allow_multiple - ]); + 'data-template-multiple' => $this->definition->allow_multiple, + ]); } public function addContainerItem($templateId, $index = null) @@ -150,7 +149,7 @@ public function moveItem($itemId, $step) ContainerContentItem::decrementBetween($this->id, $oldIndex, $item->sort_order); $item->save(); - } else if ($step < 0 && $item->sort_order != 0) { + } elseif ($step < 0 && $item->sort_order != 0) { $oldIndex = $item->sort_order; $newIndex = $oldIndex + $step; $item->sort_order = ($newIndex > 0) ? $newIndex : 0; @@ -205,9 +204,9 @@ public function isSingleAllowedTemplate() public function renderForm($form) { return TemplateContentFormFields::widget([ - 'type' => 'container', - 'form' => $form, - 'model' => $this + 'type' => 'container', + 'form' => $form, + 'model' => $this, ]); } diff --git a/modules/template/models/ContainerContentDefinition.php b/modules/template/models/ContainerContentDefinition.php index 996bb3b2..9a8c33d8 100644 --- a/modules/template/models/ContainerContentDefinition.php +++ b/modules/template/models/ContainerContentDefinition.php @@ -41,9 +41,9 @@ public function attributeLabels() public function afterSave($insert, $changedAttributes) { - $this->saveAllowedTemplateSelection(); - parent::afterSave($insert, $changedAttributes); + + $this->saveAllowedTemplateSelection(); } public function saveAllowedTemplateSelection()