Skip to content

Commit

Permalink
Merge pull request #348 from humhub/fix/347-after-save-new-page
Browse files Browse the repository at this point in the history
Fix errors after save a new page
  • Loading branch information
luke- committed Sep 24, 2024
2 parents 5fc0f90 + 7f066a7 commit 641fc49
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 17 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions models/CustomContentContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,15 +519,15 @@ 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());
}

if ($this->checkAbstract()) {
RichText::postProcess($this->abstract, $this);
}

parent::afterSave($insert, $changedAttributes);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion models/MarkdownType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -62,4 +66,4 @@ public function renderFormField(ActiveForm $form, CustomContentContainer $page)
{
return $form->field($page, $page->getPageContentProperty())->widget(RichTextField::class, [ 'pluginOptions' => ['maxHeight' => '500px']]);
}
}
}
8 changes: 6 additions & 2 deletions models/TemplateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]);
}
}
}
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 8 additions & 9 deletions modules/template/models/ContainerContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
class ContainerContent extends TemplateContentActiveRecord
{

public static $label = 'Container';

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -56,8 +57,6 @@ public function afterSave($insert, $changedAttributes)
$allowedTemplate->save();
}
}

parent::afterSave($insert, $changedAttributes);
}

public function beforeDelete()
Expand Down Expand Up @@ -112,8 +111,8 @@ public function renderEmpty($options = [])
$options['jsWidget'] = 'custom_pages.template.TemplateContainer';
return $this->renderEmptyDiv(Yii::t('CustomPagesModule.models_Container', 'Empty <br />Container'), $options, [
'class' => 'emptyContainerBlock',
'data-template-multiple' => $this->definition->allow_multiple
]);
'data-template-multiple' => $this->definition->allow_multiple,
]);
}

public function addContainerItem($templateId, $index = null)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
]);
}

Expand Down
4 changes: 2 additions & 2 deletions modules/template/models/ContainerContentDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public function attributeLabels()

public function afterSave($insert, $changedAttributes)
{
$this->saveAllowedTemplateSelection();

parent::afterSave($insert, $changedAttributes);

$this->saveAllowedTemplateSelection();
}

public function saveAllowedTemplateSelection()
Expand Down

0 comments on commit 641fc49

Please sign in to comment.