allow to create new content
This commit is contained in:
@@ -23,9 +23,12 @@
|
|||||||
|
|
||||||
namespace Thelia\Action;
|
namespace Thelia\Action;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
use Thelia\Core\Event\Content\ContentCreateEvent;
|
||||||
use Thelia\Core\Event\Content\ContentUpdateEvent;
|
use Thelia\Core\Event\Content\ContentUpdateEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
use Thelia\Model\ContentQuery;
|
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
|
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)
|
public function update(ContentUpdateEvent $event)
|
||||||
{
|
{
|
||||||
if (null !== $content = ContentQuery::create()->findPk($event->getContentId())) {
|
if (null !== $content = ContentQuery::create()->findPk($event->getContentId())) {
|
||||||
|
|||||||
@@ -222,6 +222,10 @@
|
|||||||
</route>
|
</route>
|
||||||
|
|
||||||
<!-- content routes management -->
|
<!-- content routes management -->
|
||||||
|
<route id="admin.folders.create" path="/admin/content/create">
|
||||||
|
<default key="_controller">Thelia\Controller\Admin\ContentController::createAction</default>
|
||||||
|
</route>
|
||||||
|
|
||||||
<route id="admin.content.update" path="admin/content/update/{content_id}">
|
<route id="admin.content.update" path="admin/content/update/{content_id}">
|
||||||
<default key="_controller">Thelia\Controller\Admin\ContentController::updateAction</default>
|
<default key="_controller">Thelia\Controller\Admin\ContentController::updateAction</default>
|
||||||
<requirement key="content_id">\d+</requirement>
|
<requirement key="content_id">\d+</requirement>
|
||||||
|
|||||||
@@ -108,10 +108,12 @@ class ContentController extends AbstractCrudController
|
|||||||
|
|
||||||
$contentCreateEvent
|
$contentCreateEvent
|
||||||
->setLocale($formData['locale'])
|
->setLocale($formData['locale'])
|
||||||
->setDefaultFolder($formData['default_controller'])
|
->setDefaultFolder($formData['default_folder'])
|
||||||
->setTitle($formData['title'])
|
->setTitle($formData['title'])
|
||||||
->setVisible($formData['visible'])
|
->setVisible($formData['visible'])
|
||||||
;
|
;
|
||||||
|
|
||||||
|
return $contentCreateEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -34,8 +34,13 @@ class Content extends BaseContent
|
|||||||
|
|
||||||
public function getDefaultFolderId()
|
public function getDefaultFolderId()
|
||||||
{
|
{
|
||||||
//@TODO update contentFolder Table, adding by_default column and change this code for returnin good value
|
// Find default folder
|
||||||
return $this->getFolders()->getFirst()->getId();
|
$default_folder = ContentFolderQuery::create()
|
||||||
|
->filterByContentId($this->getId())
|
||||||
|
->filterByDefaultFolder(true)
|
||||||
|
->findOne();
|
||||||
|
|
||||||
|
return $default_folder == null ? 0 : $default_folder->getFolderId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -412,11 +412,11 @@
|
|||||||
{form_hidden_fields form=$form}
|
{form_hidden_fields form=$form}
|
||||||
|
|
||||||
{* Be sure to get the folder_id, even if the form could not be validated *}
|
{* Be sure to get the folder_id, even if the form could not be validated *}
|
||||||
<input type="hidden" name="folder_id" value="{$parent}" />
|
<input type="hidden" name="parent" value="{$parent}" />
|
||||||
|
|
||||||
{form_field form=$form field='success_url'}
|
{form_field form=$form field='success_url'}
|
||||||
{* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *}
|
{* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *}
|
||||||
<input type="hidden" name="{$name}" value="{url path='/admin/contents/update' content_id='_ID_'}" />
|
<input type="hidden" name="{$name}" value="{url path='/admin/content/update/_ID_' }" />
|
||||||
{/form_field}
|
{/form_field}
|
||||||
|
|
||||||
{form_field form=$form field='default_folder'}
|
{form_field form=$form field='default_folder'}
|
||||||
@@ -468,7 +468,7 @@
|
|||||||
|
|
||||||
dialog_ok_label = {intl l="Create this content"}
|
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_enctype = {form_enctype form=$form}
|
||||||
form_error_message = $form_error_message
|
form_error_message = $form_error_message
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user