Merge branch 'master' into modules
Conflicts: templates/backOffice/default/product-edit.html
This commit is contained in:
@@ -34,7 +34,7 @@ use Thelia\Core\Event\UpdatePositionEvent;
|
||||
*/
|
||||
abstract class AbstractCrudController extends BaseAdminController
|
||||
{
|
||||
protected $objectName;
|
||||
protected $objectName;
|
||||
|
||||
// List ordering
|
||||
protected $defaultListOrder;
|
||||
@@ -139,7 +139,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
/**
|
||||
* Get the created object from an event.
|
||||
*
|
||||
* @param unknown $createEvent
|
||||
* @param unknown $event
|
||||
*/
|
||||
abstract protected function getObjectFromEvent($event);
|
||||
|
||||
@@ -230,7 +230,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
/**
|
||||
* Put in this method post object position change processing if required.
|
||||
*
|
||||
* @param unknown $deleteEvent the delete event
|
||||
* @param unknown $positionChangeEvent the delete event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalUpdatePositionAction($positionChangeEvent)
|
||||
@@ -267,7 +267,10 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
*/
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::VIEW)) return $response;
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::VIEW))
|
||||
return $response;
|
||||
|
||||
return $this->renderList();
|
||||
}
|
||||
|
||||
@@ -279,8 +282,10 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
public function createAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::CREATE)) return $response;
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::CREATE))
|
||||
return $response;
|
||||
|
||||
// Error (Default: false)
|
||||
$error_msg = false;
|
||||
|
||||
// Create the Creation Form
|
||||
@@ -288,24 +293,29 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
|
||||
try {
|
||||
|
||||
// Validate the form, create the event and dispatch it.
|
||||
// Check the form against constraints violations
|
||||
$form = $this->validateForm($creationForm, "POST");
|
||||
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
// Create a new event object with the modified fields
|
||||
$createEvent = $this->getCreationEvent($data);
|
||||
|
||||
// Dispatch Create Event
|
||||
$this->dispatch($this->createEventIdentifier, $createEvent);
|
||||
|
||||
// Check if object exist
|
||||
if (! $this->eventContainsObject($createEvent))
|
||||
throw new \LogicException(
|
||||
$this->getTranslator()->trans("No %obj was created.", array('%obj', $this->objectName)));
|
||||
$this->getTranslator()->trans("No %obj was created.", array('%obj', $this->objectName)));
|
||||
|
||||
// Log object creation
|
||||
if (null !== $createdObject = $this->getObjectFromEvent($createEvent)) {
|
||||
// Log object creation
|
||||
$this->adminLogAppend($this->resourceCode, AccessManager::CREATE, sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject)));
|
||||
}
|
||||
|
||||
// Execute additional Action
|
||||
$response = $this->performAdditionalCreateAction($createEvent);
|
||||
|
||||
if ($response == null) {
|
||||
@@ -326,7 +336,11 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("%obj creation", array('%obj' => $this->objectName)), $error_msg, $creationForm, $ex);
|
||||
$this->getTranslator()->trans("%obj creation", array('%obj' => $this->objectName)),
|
||||
$error_msg,
|
||||
$creationForm,
|
||||
$ex
|
||||
);
|
||||
|
||||
// At this point, the form has error, and should be redisplayed.
|
||||
return $this->renderList();
|
||||
@@ -340,12 +354,11 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
public function updateAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) return $response;
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE))
|
||||
return $response;
|
||||
|
||||
// Load the object
|
||||
$object = $this->getExistingObject();
|
||||
|
||||
if ($object != null) {
|
||||
// Load object if exist
|
||||
if (null !== $object = $this->getExistingObject()) {
|
||||
|
||||
// Hydrate the form abd pass it to the parser
|
||||
$changeForm = $this->hydrateObjectForm($object);
|
||||
@@ -366,11 +379,13 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
public function processUpdateAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) return $response;
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE))
|
||||
return $response;
|
||||
|
||||
// Error (Default: false)
|
||||
$error_msg = false;
|
||||
|
||||
// Create the form from the request
|
||||
// Create the Form from the request
|
||||
$changeForm = $this->getUpdateForm($this->getRequest());
|
||||
|
||||
try {
|
||||
@@ -381,23 +396,27 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
// Create a new event object with the modified fields
|
||||
$changeEvent = $this->getUpdateEvent($data);
|
||||
|
||||
// Dispatch Update Event
|
||||
$this->dispatch($this->updateEventIdentifier, $changeEvent);
|
||||
|
||||
// Check if object exist
|
||||
if (! $this->eventContainsObject($changeEvent))
|
||||
throw new \LogicException(
|
||||
$this->getTranslator()->trans("No %obj was updated.", array('%obj', $this->objectName)));
|
||||
$this->getTranslator()->trans("No %obj was updated.", array('%obj', $this->objectName)));
|
||||
|
||||
// Log object modification
|
||||
if (null !== $changedObject = $this->getObjectFromEvent($changeEvent)) {
|
||||
$this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
}
|
||||
|
||||
// Execute additional Action
|
||||
$response = $this->performAdditionalUpdateAction($changeEvent);
|
||||
|
||||
if ($response == null) {
|
||||
// If we have to stay on the same page, do not redirect to the succesUrl,
|
||||
// If we have to stay on the same page, do not redirect to the successUrl,
|
||||
// just redirect to the edit page again.
|
||||
if ($this->getRequest()->get('save_mode') == 'stay') {
|
||||
$this->redirectToEditionTemplate($this->getRequest());
|
||||
@@ -416,11 +435,16 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
$error_msg = $ex->getMessage();*/
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)), $error_msg, $changeForm, $ex);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->renderEditionTemplate();
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)),
|
||||
$error_msg,
|
||||
$changeForm,
|
||||
$ex
|
||||
);
|
||||
|
||||
|
||||
//return $this->renderEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -431,7 +455,8 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
public function updatePositionAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) return $response;
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE))
|
||||
return $response;
|
||||
|
||||
try {
|
||||
$mode = $this->getRequest()->get('mode', null);
|
||||
@@ -448,6 +473,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
$event = $this->createUpdatePositionEvent($mode, $position);
|
||||
|
||||
$this->dispatch($this->changePositionEventIdentifier, $event);
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
@@ -465,7 +491,8 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
protected function genericUpdatePositionAction($object, $eventName, $doFinalRedirect = true)
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) return $response;
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE))
|
||||
return $response;
|
||||
|
||||
if ($object != null) {
|
||||
|
||||
@@ -499,7 +526,8 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
public function setToggleVisibilityAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) return $response;
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE))
|
||||
return $response;
|
||||
|
||||
$changeEvent = $this->createToggleVisibilityEvent($this->getRequest());
|
||||
|
||||
@@ -521,7 +549,8 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
public function deleteAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::DELETE)) return $response;
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::DELETE))
|
||||
return $response;
|
||||
|
||||
// Get the currency id, and dispatch the delet request
|
||||
$deleteEvent = $this->getDeleteEvent();
|
||||
|
||||
235
core/lib/Thelia/Controller/Admin/AbstractSeoCrudController.php
Normal file
235
core/lib/Thelia/Controller/Admin/AbstractSeoCrudController.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\UpdateSeoEvent;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Form\SeoForm;
|
||||
|
||||
/**
|
||||
* Extend abstract CRUD controller to manage basic CRUD + SEO operations on a given object.
|
||||
*
|
||||
* @author Christophe Laffont <claffont@openstudio.fr>
|
||||
*/
|
||||
abstract class AbstractSeoCrudController extends AbstractCrudController
|
||||
{
|
||||
// Events
|
||||
protected $updateSeoEventIdentifier;
|
||||
|
||||
/**
|
||||
* @param string $objectName the lower case object name. Example. "message"
|
||||
*
|
||||
* @param string $defaultListOrder the default object list order, or null if list is not sortable. Example: manual
|
||||
* @param string $orderRequestParameterName Name of the request parameter that set the list order (null if list is not sortable)
|
||||
*
|
||||
* @param string $resourceCode the 'resource' code. Example: "admin.configuration.message"
|
||||
*
|
||||
* @param string $createEventIdentifier the dispatched create TheliaEvent identifier. Example: TheliaEvents::MESSAGE_CREATE
|
||||
* @param string $updateEventIdentifier the dispatched update TheliaEvent identifier. Example: TheliaEvents::MESSAGE_UPDATE
|
||||
* @param string $deleteEventIdentifier the dispatched delete TheliaEvent identifier. Example: TheliaEvents::MESSAGE_DELETE
|
||||
*
|
||||
* @param string $visibilityToggleEventIdentifier the dispatched visibility toggle TheliaEvent identifier, or null if the object has no visible options. Example: TheliaEvents::MESSAGE_TOGGLE_VISIBILITY
|
||||
* @param string $changePositionEventIdentifier the dispatched position change TheliaEvent identifier, or null if the object has no position. Example: TheliaEvents::MESSAGE_UPDATE_POSITION
|
||||
* @param string $updateSeoEventIdentifier the dispatched update SEO change TheliaEvent identifier, or null if the object has no SEO. Example: TheliaEvents::MESSAGE_UPDATE_SEO
|
||||
*/
|
||||
public function __construct(
|
||||
$objectName,
|
||||
|
||||
$defaultListOrder = null,
|
||||
$orderRequestParameterName = null,
|
||||
|
||||
$resourceCode,
|
||||
|
||||
$createEventIdentifier,
|
||||
$updateEventIdentifier,
|
||||
$deleteEventIdentifier,
|
||||
$visibilityToggleEventIdentifier = null,
|
||||
$changePositionEventIdentifier = null,
|
||||
$updateSeoEventIdentifier = null
|
||||
)
|
||||
{
|
||||
parent::__construct(
|
||||
$objectName,
|
||||
$defaultListOrder,
|
||||
$orderRequestParameterName,
|
||||
$resourceCode,
|
||||
$createEventIdentifier,
|
||||
$updateEventIdentifier,
|
||||
$deleteEventIdentifier,
|
||||
$visibilityToggleEventIdentifier,
|
||||
$changePositionEventIdentifier
|
||||
);
|
||||
|
||||
$this->updateSeoEventIdentifier = $updateSeoEventIdentifier;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Put in this method post object update SEO processing if required.
|
||||
*
|
||||
* @param unknown $updateSeoEvent the update event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalUpdateSeoAction($updateSeoEvent)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the update SEO form for this object
|
||||
*/
|
||||
protected function getUpdateSeoForm()
|
||||
{
|
||||
return new SeoForm($this->getRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the update SEO event with the provided form data
|
||||
*
|
||||
* @param $formData
|
||||
* @return UpdateSeoEvent
|
||||
*/
|
||||
protected function getUpdateSeoEvent($formData)
|
||||
{
|
||||
|
||||
$updateSeoEvent = new UpdateSeoEvent($formData['id']);
|
||||
|
||||
$updateSeoEvent
|
||||
->setLocale($formData['locale'])
|
||||
->setMetaTitle($formData['meta_title'])
|
||||
->setMetaDescription($formData['meta_description'])
|
||||
->setMetaKeywords($formData['meta_keywords'])
|
||||
->setUrl($formData['url'])
|
||||
;
|
||||
|
||||
// Create and dispatch the change event
|
||||
return $updateSeoEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate the SEO form for this object, before passing it to the update template
|
||||
*
|
||||
* @param unknown $object
|
||||
*/
|
||||
protected function hydrateSeoForm($object){
|
||||
// The "SEO" tab form
|
||||
$locale = $object->getLocale();
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
'locale' => $locale,
|
||||
'url' => $object->getRewrittenUrl($locale),
|
||||
'meta_title' => $object->getMetaTitle(),
|
||||
'meta_description' => $object->getMetaDescription(),
|
||||
'meta_keywords' => $object->getMetaKeywords()
|
||||
);
|
||||
|
||||
$seoForm = new SeoForm($this->getRequest(), "form", $data);
|
||||
$this->getParserContext()->addForm($seoForm);
|
||||
|
||||
// URL based on the language
|
||||
$this->getParserContext()->set('url_language', $this->getUrlLanguage($locale));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update SEO modification, and either go back to the object list, or stay on the edition page.
|
||||
*
|
||||
* @return Thelia\Core\HttpFoundation\Response the response
|
||||
*/
|
||||
public function processUpdateSeoAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE))
|
||||
return $response;
|
||||
|
||||
// Error (Default: false)
|
||||
$error_msg = false;
|
||||
|
||||
// Create the Form from the request
|
||||
$updateSeoForm = $this->getUpdateSeoForm($this->getRequest());
|
||||
|
||||
// Pass the object id to the request
|
||||
$this->getRequest()->attributes->set($this->objectName . '_id', $this->getRequest()->get('current_id'));
|
||||
|
||||
try {
|
||||
|
||||
// Check the form against constraints violations
|
||||
$form = $this->validateForm($updateSeoForm, "POST");
|
||||
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
// Create a new event object with the modified fields
|
||||
$updateSeoEvent = $this->getUpdateSeoEvent($data);
|
||||
|
||||
// Dispatch Update SEO Event
|
||||
$this->dispatch($this->updateSeoEventIdentifier, $updateSeoEvent);
|
||||
|
||||
// Execute additional Action
|
||||
$response = $this->performAdditionalUpdateSeoAction($updateSeoEvent);
|
||||
|
||||
if ($response == null) {
|
||||
// If we have to stay on the same page, do not redirect to the successUrl,
|
||||
// just redirect to the edit page again.
|
||||
if ($this->getRequest()->get('save_mode') == 'stay') {
|
||||
$this->redirectToEditionTemplate($this->getRequest());
|
||||
}
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($updateSeoForm->getSuccessUrl());
|
||||
} else {
|
||||
return $response;
|
||||
}
|
||||
} catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
/*} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex->getMessage();*/
|
||||
}
|
||||
|
||||
// Load object if exist
|
||||
if (null !== $object = $this->getExistingObject()) {
|
||||
|
||||
// Hydrate the form abd pass it to the parser
|
||||
$changeForm = $this->hydrateObjectForm($object);
|
||||
|
||||
// Pass it to the parser
|
||||
$this->getParserContext()->addForm($changeForm);
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("%obj SEO modification", array('%obj' => $this->objectName)),
|
||||
$error_msg,
|
||||
$updateSeoForm,
|
||||
$ex
|
||||
);
|
||||
|
||||
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->renderEditionTemplate();
|
||||
}
|
||||
}
|
||||
@@ -302,6 +302,23 @@ class BaseAdminController extends BaseController
|
||||
return $this->getCurrentEditionLang()->getLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple helper to get the URL based on the language.
|
||||
*/
|
||||
protected function getUrlLanguage($locale = null)
|
||||
{
|
||||
// Check if the functionality is activated
|
||||
if(!ConfigQuery::read("one_domain_foreach_lang", false))
|
||||
return;
|
||||
|
||||
// If we don't have a locale value, use the locale value in the session
|
||||
if(!$locale)
|
||||
$locale = $this->getCurrentEditionLocale();
|
||||
|
||||
return LangQuery::create()->findOneByLocale($locale)->getUrl();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the current list order identifier for a given object name,
|
||||
* updating in using the current request.
|
||||
|
||||
@@ -47,7 +47,7 @@ use Thelia\Model\CategoryAssociatedContentQuery;
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class CategoryController extends AbstractCrudController
|
||||
class CategoryController extends AbstractSeoCrudController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
@@ -62,7 +62,8 @@ class CategoryController extends AbstractCrudController
|
||||
TheliaEvents::CATEGORY_UPDATE,
|
||||
TheliaEvents::CATEGORY_DELETE,
|
||||
TheliaEvents::CATEGORY_TOGGLE_VISIBILITY,
|
||||
TheliaEvents::CATEGORY_UPDATE_POSITION
|
||||
TheliaEvents::CATEGORY_UPDATE_POSITION,
|
||||
TheliaEvents::CATEGORY_UPDATE_SEO
|
||||
);
|
||||
}
|
||||
|
||||
@@ -102,7 +103,6 @@ class CategoryController extends AbstractCrudController
|
||||
->setDescription($formData['description'])
|
||||
->setPostscriptum($formData['postscriptum'])
|
||||
->setVisible($formData['visible'])
|
||||
->setUrl($formData['url'])
|
||||
->setParent($formData['parent'])
|
||||
;
|
||||
|
||||
@@ -130,7 +130,10 @@ class CategoryController extends AbstractCrudController
|
||||
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
// Prepare the data that will hydrate the form
|
||||
// Hydrate the "SEO" tab form
|
||||
$this->hydrateSeoForm($object);
|
||||
|
||||
// The "General" tab form
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
'locale' => $object->getLocale(),
|
||||
@@ -139,7 +142,6 @@ class CategoryController extends AbstractCrudController
|
||||
'description' => $object->getDescription(),
|
||||
'postscriptum' => $object->getPostscriptum(),
|
||||
'visible' => $object->getVisible(),
|
||||
'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()),
|
||||
'parent' => $object->getParent()
|
||||
);
|
||||
|
||||
@@ -193,10 +195,25 @@ class CategoryController extends AbstractCrudController
|
||||
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
$category_id = $this->getRequest()->get('category_id', 0);
|
||||
$this->redirectToListTemplateWithId($category_id);
|
||||
}
|
||||
|
||||
protected function redirectToListTemplateWithId($category_id)
|
||||
{
|
||||
if($category_id > 0)
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
'admin.categories.default',
|
||||
array('category_id' => $this->getRequest()->get('category_id', 0))
|
||||
);
|
||||
array('category_id' => $category_id)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
'admin.catalog'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function renderEditionTemplate()
|
||||
@@ -233,21 +250,16 @@ class CategoryController extends AbstractCrudController
|
||||
protected function performAdditionalDeleteAction($deleteEvent)
|
||||
{
|
||||
// Redirect to parent category list
|
||||
$this->redirectToRoute(
|
||||
'admin.categories.default',
|
||||
array('category_id' => $deleteEvent->getCategory()->getParent())
|
||||
);
|
||||
$category_id = $deleteEvent->getCategory()->getParent();
|
||||
$this->redirectToListTemplateWithId($category_id);
|
||||
}
|
||||
|
||||
protected function performAdditionalUpdateAction($updateEvent)
|
||||
{
|
||||
if ($this->getRequest()->get('save_mode') != 'stay') {
|
||||
|
||||
// Redirect to parent category list
|
||||
$this->redirectToRoute(
|
||||
'admin.categories.default',
|
||||
array('category_id' => $updateEvent->getCategory()->getParent())
|
||||
);
|
||||
$category_id = $updateEvent->getCategory()->getParent();
|
||||
$this->redirectToListTemplateWithId($category_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,10 +270,8 @@ class CategoryController extends AbstractCrudController
|
||||
|
||||
if ($category != null) {
|
||||
// Redirect to parent category list
|
||||
$this->redirectToRoute(
|
||||
'admin.categories.default',
|
||||
array('category_id' => $category->getParent())
|
||||
);
|
||||
$category_id = $category->getParent();
|
||||
$this->redirectToListTemplateWithId($category_id);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -41,7 +41,7 @@ use Thelia\Model\ContentQuery;
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author manuel raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ContentController extends AbstractCrudController
|
||||
class ContentController extends AbstractSeoCrudController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
@@ -57,7 +57,8 @@ class ContentController extends AbstractCrudController
|
||||
TheliaEvents::CONTENT_UPDATE,
|
||||
TheliaEvents::CONTENT_DELETE,
|
||||
TheliaEvents::CONTENT_TOGGLE_VISIBILITY,
|
||||
TheliaEvents::CONTENT_UPDATE_POSITION
|
||||
TheliaEvents::CONTENT_UPDATE_POSITION,
|
||||
TheliaEvents::CONTENT_UPDATE_SEO
|
||||
);
|
||||
}
|
||||
|
||||
@@ -140,6 +141,9 @@ class ContentController extends AbstractCrudController
|
||||
*/
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
// Hydrate the "SEO" tab form
|
||||
$this->hydrateSeoForm($object);
|
||||
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
@@ -148,8 +152,7 @@ class ContentController extends AbstractCrudController
|
||||
'chapo' => $object->getChapo(),
|
||||
'description' => $object->getDescription(),
|
||||
'postscriptum' => $object->getPostscriptum(),
|
||||
'visible' => $object->getVisible(),
|
||||
'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()),
|
||||
'visible' => $object->getVisible()
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
@@ -191,7 +194,6 @@ class ContentController extends AbstractCrudController
|
||||
->setDescription($formData['description'])
|
||||
->setPostscriptum($formData['postscriptum'])
|
||||
->setVisible($formData['visible'])
|
||||
->setUrl($formData['url'])
|
||||
->setDefaultFolder($formData['default_folder']);
|
||||
|
||||
return $contentUpdateEvent;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Event\Folder\FolderCreateEvent;
|
||||
use Thelia\Core\Event\Folder\FolderDeleteEvent;
|
||||
@@ -38,7 +39,7 @@ use Thelia\Model\FolderQuery;
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class FolderController extends AbstractCrudController
|
||||
class FolderController extends AbstractSeoCrudController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
@@ -54,7 +55,8 @@ class FolderController extends AbstractCrudController
|
||||
TheliaEvents::FOLDER_UPDATE,
|
||||
TheliaEvents::FOLDER_DELETE,
|
||||
TheliaEvents::FOLDER_TOGGLE_VISIBILITY,
|
||||
TheliaEvents::FOLDER_UPDATE_POSITION
|
||||
TheliaEvents::FOLDER_UPDATE_POSITION,
|
||||
TheliaEvents::FOLDER_UPDATE_SEO
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,6 +83,9 @@ class FolderController extends AbstractCrudController
|
||||
*/
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
// Hydrate the "SEO" tab form
|
||||
$this->hydrateSeoForm($object);
|
||||
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
@@ -90,7 +95,6 @@ class FolderController extends AbstractCrudController
|
||||
'description' => $object->getDescription(),
|
||||
'postscriptum' => $object->getPostscriptum(),
|
||||
'visible' => $object->getVisible(),
|
||||
'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()),
|
||||
'parent' => $object->getParent()
|
||||
);
|
||||
|
||||
@@ -132,7 +136,6 @@ class FolderController extends AbstractCrudController
|
||||
->setDescription($formData['description'])
|
||||
->setPostscriptum($formData['postscriptum'])
|
||||
->setVisible($formData['visible'])
|
||||
->setUrl($formData['url'])
|
||||
->setParent($formData['parent'])
|
||||
;
|
||||
|
||||
@@ -247,11 +250,15 @@ class FolderController extends AbstractCrudController
|
||||
return $this->render('folder-edit', $this->getEditionArguments());
|
||||
}
|
||||
|
||||
protected function getEditionArguments()
|
||||
protected function getEditionArguments(Request $request = null)
|
||||
{
|
||||
if (null === $request) {
|
||||
$request = $this->getRequest();
|
||||
}
|
||||
|
||||
return array(
|
||||
'folder_id' => $this->getRequest()->get('folder_id', 0),
|
||||
'current_tab' => $this->getRequest()->get('current_tab', 'general')
|
||||
'folder_id' => $request->get('folder_id', 0),
|
||||
'current_tab' => $request->get('current_tab', 'general')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -309,9 +316,9 @@ class FolderController extends AbstractCrudController
|
||||
/**
|
||||
* Redirect to the edition template
|
||||
*/
|
||||
protected function redirectToEditionTemplate()
|
||||
protected function redirectToEditionTemplate(Request $request = null)
|
||||
{
|
||||
$this->redirect($this->getRoute('admin.folders.update', $this->getEditionArguments()));
|
||||
$this->redirect($this->getRoute('admin.folders.update', $this->getEditionArguments($request)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,57 +23,62 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Event\Product\ProductAddCategoryEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteCategoryEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteEvent;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\Product\ProductUpdateEvent;
|
||||
use Thelia\Core\Event\Product\ProductCreateEvent;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Form\ProductModificationForm;
|
||||
use Thelia\Form\ProductCreationForm;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\Product\ProductAddCategoryEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteCategoryEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteEvent;
|
||||
use Thelia\Core\Event\Product\ProductToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteContentEvent;
|
||||
use Thelia\Core\Event\Product\ProductAddContentEvent;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Model\ProductAssociatedContentQuery;
|
||||
use Thelia\Model\AccessoryQuery;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
|
||||
use Thelia\Core\Event\Product\ProductAddAccessoryEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteAccessoryEvent;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
use Thelia\Core\Event\Product\ProductCombinationGenerationEvent;
|
||||
use Thelia\Core\Event\Product\ProductSetTemplateEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\ProductSaleElement\ProductSaleElementDeleteEvent;
|
||||
use Thelia\Core\Event\ProductSaleElement\ProductSaleElementUpdateEvent;
|
||||
use Thelia\Core\Event\ProductSaleElement\ProductSaleElementCreateEvent;
|
||||
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
|
||||
use Thelia\Model\AccessoryQuery;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Thelia\Model\AttributeQuery;
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Form\ProductSaleElementUpdateForm;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\ProductAssociatedContentQuery;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
use Thelia\Model\ProductPriceQuery;
|
||||
use Thelia\Form\ProductDefaultSaleElementUpdateForm;
|
||||
use Thelia\Model\ProductPrice;
|
||||
use Thelia\Model\Currency;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Thelia\TaxEngine\Calculator;
|
||||
use Thelia\Model\Country;
|
||||
use Thelia\Tools\NumberFormat;
|
||||
use Thelia\Model\Product;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\Country;
|
||||
use Thelia\Model\Product;
|
||||
|
||||
use Thelia\Form\ProductCreationForm;
|
||||
use Thelia\Form\ProductModificationForm;
|
||||
use Thelia\Form\ProductSaleElementUpdateForm;
|
||||
use Thelia\Form\ProductDefaultSaleElementUpdateForm;
|
||||
use Thelia\Form\ProductCombinationGenerationForm;
|
||||
use Thelia\Core\Event\Product\ProductCombinationGenerationEvent;
|
||||
use Thelia\Core\Event\Product\ProductSetTemplateEvent;
|
||||
|
||||
use Thelia\TaxEngine\Calculator;
|
||||
use Thelia\Tools\NumberFormat;
|
||||
|
||||
|
||||
/**
|
||||
* Manages products
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class ProductController extends AbstractCrudController
|
||||
class ProductController extends AbstractSeoCrudController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
@@ -89,7 +94,8 @@ class ProductController extends AbstractCrudController
|
||||
TheliaEvents::PRODUCT_DELETE,
|
||||
|
||||
TheliaEvents::PRODUCT_TOGGLE_VISIBILITY,
|
||||
TheliaEvents::PRODUCT_UPDATE_POSITION
|
||||
TheliaEvents::PRODUCT_UPDATE_POSITION,
|
||||
TheliaEvents::PRODUCT_UPDATE_SEO
|
||||
);
|
||||
}
|
||||
|
||||
@@ -153,9 +159,9 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
|
||||
$changeEvent = new ProductUpdateEvent($formData['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent
|
||||
->setLocale($formData['locale'])
|
||||
->setTitle($formData['title'])
|
||||
@@ -163,10 +169,10 @@ class ProductController extends AbstractCrudController
|
||||
->setDescription($formData['description'])
|
||||
->setPostscriptum($formData['postscriptum'])
|
||||
->setVisible($formData['visible'])
|
||||
->setUrl($formData['url'])
|
||||
->setDefaultCategory($formData['default_category'])
|
||||
;
|
||||
;
|
||||
|
||||
// Create and dispatch the change event
|
||||
return $changeEvent;
|
||||
}
|
||||
|
||||
@@ -307,6 +313,9 @@ class ProductController extends AbstractCrudController
|
||||
$this->getParserContext()->addForm($combinationPseForm);
|
||||
}
|
||||
|
||||
// Hydrate the "SEO" tab form
|
||||
$this->hydrateSeoForm($object);
|
||||
|
||||
// The "General" tab form
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
@@ -317,7 +326,6 @@ class ProductController extends AbstractCrudController
|
||||
'description' => $object->getDescription(),
|
||||
'postscriptum' => $object->getPostscriptum(),
|
||||
'visible' => $object->getVisible(),
|
||||
'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()),
|
||||
'default_category' => $object->getDefaultCategoryId()
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user