/** * Toggle category visibility. No form used here * * @param ActionEvent $event */ public function toggleVisibility(CategoryToggleVisibilityEvent $event) { $category = $event->getCategory(); $category->setDispatcher($event->getDispatcher())->setVisible($category->getVisible() ? false : true)->save(); $event->setCategory($category); }
public function testToggleVisibility() { $category = $this->getRandomCategory(); $expectedVisibility = !$category->getVisible(); $event = new CategoryToggleVisibilityEvent($category); $event->setDispatcher($this->getDispatcher()); $action = new Category(); $action->toggleVisibility($event); $updatedCategory = $event->getCategory(); $this->assertInstanceOf('Thelia\\Model\\Category', $updatedCategory); $this->assertEquals($expectedVisibility, $updatedCategory->getVisible()); }
/** * Toggle category visibility. No form used here * * @param CategoryToggleVisibilityEvent $event * @param $eventName * @param EventDispatcherInterface $dispatcher */ public function toggleVisibility(CategoryToggleVisibilityEvent $event, $eventName, EventDispatcherInterface $dispatcher) { $category = $event->getCategory(); $category->setDispatcher($dispatcher)->setVisible($category->getVisible() ? false : true)->save(); $event->setCategory($category); }