Category visibility toggle implementation

This commit is contained in:
franck
2013-08-08 10:12:14 +02:00
parent 64031a1883
commit efa3eb2767
6 changed files with 111 additions and 34 deletions

View File

@@ -235,6 +235,29 @@ class Category implements EventSubscriberInterface
$event->stopPropagation();
}
/**
* Toggle category visibility. No form used here
*
* @param ActionEvent $event
*/
public function toggleVisibility(ActionEvent $event)
{
$request = $event->getRequest();
$category = CategoryQuery::create()->findPk($request->get('id', 0));
if ($category !== null) {
$category->setVisible($category->getVisible() ? false : true);
$category->save();
$categoryEvent = new CategoryEvent($category);
$event->getDispatcher()->dispatch(TheliaEvents::AFTER_CHANGECATEGORY, $categoryEvent);
}
}
/**
* Returns an array of event names this subscriber listens to.
*
@@ -261,6 +284,8 @@ class Category implements EventSubscriberInterface
"action.createCategory" => array("create", 128),
"action.modifyCategory" => array("modify", 128),
"action.deleteCategory" => array("delete", 128),
);
"action.toggleCategoryVisibility" => array("toggleVisibility", 128),
);
}
}