diff --git a/core/lib/Thelia/Action/Content.php b/core/lib/Thelia/Action/Content.php
index 1fa91fa15..57ba90867 100644
--- a/core/lib/Thelia/Action/Content.php
+++ b/core/lib/Thelia/Action/Content.php
@@ -23,9 +23,12 @@
namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Thelia\Core\Event\Content\ContentCreateEvent;
use Thelia\Core\Event\Content\ContentUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\ContentQuery;
+use Thelia\Model\Content as ContentModel;
+use Thelia\Model\FolderQuery;
/**
@@ -36,6 +39,26 @@ use Thelia\Model\ContentQuery;
class Content extends BaseAction implements EventSubscriberInterface
{
+ public function create(ContentCreateEvent $event)
+ {
+ $content = new ContentModel();
+
+ $content
+ ->setVisible($event->getVisible())
+ ->setLocale($event->getLocale())
+ ->setTitle($event->getTitle())
+ ->addFolder(FolderQuery::create()->findPk($event->getDefaultFolder()))
+ ->save()
+ ;
+
+ $event->setContent($content);
+ }
+
+ /**
+ * process update content
+ *
+ * @param ContentUpdateEvent $event
+ */
public function update(ContentUpdateEvent $event)
{
if (null !== $content = ContentQuery::create()->findPk($event->getContentId())) {
diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml
index 8ced3500a..838bd6da8 100755
--- a/core/lib/Thelia/Config/Resources/routing/admin.xml
+++ b/core/lib/Thelia/Config/Resources/routing/admin.xml
@@ -222,6 +222,10 @@
+
+ Thelia\Controller\Admin\ContentController::createAction
+
+
Thelia\Controller\Admin\ContentController::updateAction
\d+
diff --git a/core/lib/Thelia/Controller/Admin/ContentController.php b/core/lib/Thelia/Controller/Admin/ContentController.php
index 176115a1f..9d20830a8 100644
--- a/core/lib/Thelia/Controller/Admin/ContentController.php
+++ b/core/lib/Thelia/Controller/Admin/ContentController.php
@@ -108,10 +108,12 @@ class ContentController extends AbstractCrudController
$contentCreateEvent
->setLocale($formData['locale'])
- ->setDefaultFolder($formData['default_controller'])
+ ->setDefaultFolder($formData['default_folder'])
->setTitle($formData['title'])
->setVisible($formData['visible'])
;
+
+ return $contentCreateEvent;
}
/**
diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php
index 79c66dc0f..47e90ab09 100755
--- a/core/lib/Thelia/Model/Content.php
+++ b/core/lib/Thelia/Model/Content.php
@@ -34,8 +34,13 @@ class Content extends BaseContent
public function getDefaultFolderId()
{
- //@TODO update contentFolder Table, adding by_default column and change this code for returnin good value
- return $this->getFolders()->getFirst()->getId();
+ // Find default folder
+ $default_folder = ContentFolderQuery::create()
+ ->filterByContentId($this->getId())
+ ->filterByDefaultFolder(true)
+ ->findOne();
+
+ return $default_folder == null ? 0 : $default_folder->getFolderId();
}
diff --git a/templates/admin/default/folders.html b/templates/admin/default/folders.html
index b7d435e88..fca34ba21 100644
--- a/templates/admin/default/folders.html
+++ b/templates/admin/default/folders.html
@@ -412,11 +412,11 @@
{form_hidden_fields form=$form}
{* Be sure to get the folder_id, even if the form could not be validated *}
-
+
{form_field form=$form field='success_url'}
{* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *}
-
+
{/form_field}
{form_field form=$form field='default_folder'}
@@ -468,7 +468,7 @@
dialog_ok_label = {intl l="Create this content"}
- form_action = {url path='/admin/contents/create'}
+ form_action = {url path='/admin/content/create'}
form_enctype = {form_enctype form=$form}
form_error_message = $form_error_message
}