allow update content position number
This commit is contained in:
@@ -26,6 +26,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\Content\ContentCreateEvent;
|
||||
use Thelia\Core\Event\Content\ContentUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Thelia\Model\Content as ContentModel;
|
||||
use Thelia\Model\FolderQuery;
|
||||
@@ -77,6 +78,25 @@ class Content extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function updatePosition(UpdatePositionEvent $event)
|
||||
{
|
||||
if(null !== $content = ContentQuery::create()->findPk($event->getObjectId())) {
|
||||
$content->setDispatcher($this->getDispatcher());
|
||||
|
||||
switch($event->getMode())
|
||||
{
|
||||
case UpdatePositionEvent::POSITION_ABSOLUTE:
|
||||
$content->changeAbsolutePosition($event->getPosition());
|
||||
break;
|
||||
case UpdatePositionEvent::POSITION_DOWN:
|
||||
$content->movePositionDown();
|
||||
break;
|
||||
case UpdatePositionEvent::POSITION_UP:
|
||||
$content->movePositionUp();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
|
||||
@@ -235,6 +235,10 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::processUpdateAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.content.update-position" path="/admin/content/update-position">
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::updatePositionAction</default>
|
||||
</route>
|
||||
|
||||
|
||||
<!-- Route to the Coupon controller (process Coupon browsing) -->
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Thelia\Controller\Admin;
|
||||
use Thelia\Core\Event\Content\ContentCreateEvent;
|
||||
use Thelia\Core\Event\Content\ContentUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Form\ContentCreationForm;
|
||||
use Thelia\Form\ContentModificationForm;
|
||||
use Thelia\Model\ContentQuery;
|
||||
@@ -286,4 +287,31 @@ class ContentController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $event \Thelia\Core\Event\UpdatePositionEvent
|
||||
* @return null|Response
|
||||
*/
|
||||
protected function performAdditionalUpdatePositionAction($event)
|
||||
{
|
||||
|
||||
if (null !== $content = ContentQuery::create()->findPk($event->getObjectId())) {
|
||||
// Redirect to parent category list
|
||||
$this->redirectToRoute(
|
||||
'admin.folders.default',
|
||||
array('parent' => $content->getDefaultFolderId())
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
|
||||
{
|
||||
return new UpdatePositionEvent(
|
||||
$this->getRequest()->get('content_id', null),
|
||||
$positionChangeMode,
|
||||
$positionValue
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user