implement process for changing folder position
This commit is contained in:
@@ -28,6 +28,7 @@ use Thelia\Core\Event\FolderDeleteEvent;
|
|||||||
use Thelia\Core\Event\FolderToggleVisibilityEvent;
|
use Thelia\Core\Event\FolderToggleVisibilityEvent;
|
||||||
use Thelia\Core\Event\FolderUpdateEvent;
|
use Thelia\Core\Event\FolderUpdateEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
|
use Thelia\Core\Event\UpdatePositionEvent;
|
||||||
use Thelia\Model\FolderQuery;
|
use Thelia\Model\FolderQuery;
|
||||||
use Thelia\Model\Folder as FolderModel;
|
use Thelia\Model\Folder as FolderModel;
|
||||||
|
|
||||||
@@ -100,6 +101,26 @@ class Folder extends BaseAction implements EventSubscriberInterface {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updatePosition(UpdatePositionEvent $event)
|
||||||
|
{
|
||||||
|
if(null !== $folder = FolderQuery::create()->findPk($event->getObjectId())) {
|
||||||
|
$folder->setDispatcher($this->getDispatcher());
|
||||||
|
|
||||||
|
switch($event->getMode())
|
||||||
|
{
|
||||||
|
case UpdatePositionEvent::POSITION_ABSOLUTE:
|
||||||
|
$folder->changeAbsolutePosition($event->getPosition());
|
||||||
|
break;
|
||||||
|
case UpdatePositionEvent::POSITION_DOWN:
|
||||||
|
$folder->movePositionDown();
|
||||||
|
break;
|
||||||
|
case UpdatePositionEvent::POSITION_UP:
|
||||||
|
$folder->movePositionUp();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of event names this subscriber wants to listen to.
|
* Returns an array of event names this subscriber wants to listen to.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -216,6 +216,10 @@
|
|||||||
<default key="_controller">Thelia\Controller\Admin\FolderController::deleteAction</default>
|
<default key="_controller">Thelia\Controller\Admin\FolderController::deleteAction</default>
|
||||||
</route>
|
</route>
|
||||||
|
|
||||||
|
<route id="admin.folders.update-position" path="/admin/folders/update-position">
|
||||||
|
<default key="_controller">Thelia\Controller\Admin\FolderController::updatePositionAction</default>
|
||||||
|
</route>
|
||||||
|
|
||||||
<!-- Route to the Coupon controller (process Coupon browsing) -->
|
<!-- Route to the Coupon controller (process Coupon browsing) -->
|
||||||
|
|
||||||
<route id="admin.coupon.list" path="/admin/coupon/">
|
<route id="admin.coupon.list" path="/admin/coupon/">
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ use Thelia\Core\Event\FolderDeleteEvent;
|
|||||||
use Thelia\Core\Event\FolderToggleVisibilityEvent;
|
use Thelia\Core\Event\FolderToggleVisibilityEvent;
|
||||||
use Thelia\Core\Event\FolderUpdateEvent;
|
use Thelia\Core\Event\FolderUpdateEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
|
use Thelia\Core\Event\UpdatePositionEvent;
|
||||||
use Thelia\Form\FolderCreationForm;
|
use Thelia\Form\FolderCreationForm;
|
||||||
use Thelia\Form\FolderModificationForm;
|
use Thelia\Form\FolderModificationForm;
|
||||||
use Thelia\Model\FolderQuery;
|
use Thelia\Model\FolderQuery;
|
||||||
@@ -149,13 +150,27 @@ class FolderController extends AbstractCrudController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return FolderToggleVisibilityEvent|void
|
||||||
*/
|
*/
|
||||||
protected function createToggleVisibilityEvent()
|
protected function createToggleVisibilityEvent()
|
||||||
{
|
{
|
||||||
return new FolderToggleVisibilityEvent($this->getExistingObject());
|
return new FolderToggleVisibilityEvent($this->getExistingObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $positionChangeMode
|
||||||
|
* @param $positionValue
|
||||||
|
* @return UpdatePositionEvent|void
|
||||||
|
*/
|
||||||
|
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
|
||||||
|
|
||||||
|
return new UpdatePositionEvent(
|
||||||
|
$this->getRequest()->get('folder_id', null),
|
||||||
|
$positionChangeMode,
|
||||||
|
$positionValue
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if the event contains the object, e.g. the action has updated the object in the event.
|
* Return true if the event contains the object, e.g. the action has updated the object in the event.
|
||||||
*
|
*
|
||||||
@@ -272,6 +287,26 @@ class FolderController extends AbstractCrudController
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $event \Thelia\Core\Event\UpdatePositionEvent
|
||||||
|
* @return null|Response
|
||||||
|
*/
|
||||||
|
protected function performAdditionalUpdatePositionAction($event)
|
||||||
|
{
|
||||||
|
|
||||||
|
$folder = FolderQuery::create()->findPk($event->getObjectId());
|
||||||
|
|
||||||
|
if ($folder != null) {
|
||||||
|
// Redirect to parent category list
|
||||||
|
$this->redirectToRoute(
|
||||||
|
'admin.folders.default',
|
||||||
|
array('folder_id' => $folder->getParent())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redirect to the edition template
|
* Redirect to the edition template
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user