diff --git a/core/lib/Thelia/Action/Content.php b/core/lib/Thelia/Action/Content.php
index af88fbe2b..300e269f6 100644
--- a/core/lib/Thelia/Action/Content.php
+++ b/core/lib/Thelia/Action/Content.php
@@ -74,6 +74,8 @@ class Content extends BaseAction implements EventSubscriberInterface
->save()
;
+ $content->updateDefaultFolder($event->getDefaultFolder());
+
$event->setContent($content);
}
}
diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php
index 69ef7d6d7..6417c8b56 100755
--- a/core/lib/Thelia/Model/Content.php
+++ b/core/lib/Thelia/Model/Content.php
@@ -55,6 +55,47 @@ class Content extends BaseContent
return $this;
}
+
+ public function updateDefaultFolder($defaultFolderId)
+ {
+ // Allow uncategorized content (NULL instead of 0, to bypass delete cascade constraint)
+ if ($defaultFolderId <= 0) {
+ $defaultFolderId = NULL;
+ }
+
+ if ($defaultFolderId == $this->getDefaultFolderId()) {
+ return;
+ }
+
+ ContentFolderQuery::create()
+ ->filterByContentId($this->getId())
+ ->update(array('DefaultFolder' => 0));
+
+ $contentFolder = ContentFolderQuery::create()
+ ->filterByContentId($this->getId())
+ ->filterByFolderId($defaultFolderId)
+ ->findOne();
+
+ if (null === $contentFolder) {
+ $contentFolder = new ContentFolder();
+
+ $contentFolder->setContentId($this->getId())
+ ->setFolderId($defaultFolderId);
+ }
+
+ $contentFolder->setDefaultFolder(true)
+ ->save();
+
+ }
+
+ /**
+ * Create a new content.
+ *
+ * Here pre and post insert event are fired
+ *
+ * @param $defaultFolderId
+ * @throws \Exception
+ */
public function create($defaultFolderId)
{
$con = Propel::getWriteConnection(ContentTableMap::DATABASE_NAME);
diff --git a/templates/admin/default/content-edit.html b/templates/admin/default/content-edit.html
index 64b4b780c..9be698560 100644
--- a/templates/admin/default/content-edit.html
+++ b/templates/admin/default/content-edit.html
@@ -102,7 +102,7 @@
{$myparent=$DEFAULT_FOLDER}
{loop name="fold-parent" type="folder-tree" visible="*" folder="0"}
-
+
{/loop }