allow possibility to change folder visibility

This commit is contained in:
Manuel Raynaud
2013-09-20 20:23:49 +02:00
parent a8dddc9c26
commit abac607534
5 changed files with 62 additions and 6 deletions

View File

@@ -25,6 +25,7 @@ namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\FolderCreateEvent;
use Thelia\Core\Event\FolderDeleteEvent;
use Thelia\Core\Event\FolderToggleVisibilityEvent;
use Thelia\Core\Event\FolderUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\FolderQuery;
@@ -88,6 +89,17 @@ class Folder extends BaseAction implements EventSubscriberInterface {
$event->setFolder($folder);
}
public function toggleVisibility(FolderToggleVisibilityEvent $event)
{
$folder = $event->getFolder();
$folder
->setDispatcher($this->getDispatcher())
->setVisible(!$folder->getVisible())
->save();
}
/**
* Returns an array of event names this subscriber wants to listen to.
*

View File

@@ -204,11 +204,15 @@
<default key="_controller">Thelia\Controller\Admin\FolderController::updateAction</default>
</route>
<route id="admin.categories.save" path="/admin/folders/save">
<route id="admin.folders.toggle-online" path="/admin/folders/toggle-online">
<default key="_controller">Thelia\Controller\Admin\FolderController::setToggleVisibilityAction</default>
</route>
<route id="admin.folders.save" path="/admin/folders/save">
<default key="_controller">Thelia\Controller\Admin\FolderController::processUpdateAction</default>
</route>
<route id="admin.categories.delete" path="/admin/folders/delete">
<route id="admin.folders.delete" path="/admin/folders/delete">
<default key="_controller">Thelia\Controller\Admin\FolderController::deleteAction</default>
</route>

View File

@@ -492,9 +492,6 @@ abstract class AbstractCrudController extends BaseAdminController
$changeEvent = $this->createToggleVisibilityEvent($this->getRequest());
// Create and dispatch the change event
$changeEvent->setIsDefault(true);
try {
$this->dispatch($this->visibilityToggleEventIdentifier, $changeEvent);
} catch (\Exception $ex) {
@@ -502,7 +499,7 @@ abstract class AbstractCrudController extends BaseAdminController
return $this->errorPage($ex);
}
$this->redirectToListTemplate();
return $this->nullResponse();
}
/**

View File

@@ -24,6 +24,7 @@
namespace Thelia\Controller\Admin;
use Thelia\Core\Event\FolderCreateEvent;
use Thelia\Core\Event\FolderDeleteEvent;
use Thelia\Core\Event\FolderToggleVisibilityEvent;
use Thelia\Core\Event\FolderUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\FolderCreationForm;
@@ -147,6 +148,14 @@ class FolderController extends AbstractCrudController
return new FolderDeleteEvent($this->getRequest()->get('folder_id'), 0);
}
/**
*
*/
protected function createToggleVisibilityEvent()
{
return new FolderToggleVisibilityEvent($this->getExistingObject());
}
/**
* Return true if the event contains the object, e.g. the action has updated the object in the event.
*

View File

@@ -0,0 +1,34 @@
<?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\Core\Event;
/**
* Class FolderToggleVisibilityEvent
* @package Thelia\Core\Event
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class FolderToggleVisibilityEvent extends FolderEvent {
}