示例#1
0
 /**
  * Prevent channel deletion if no more channels enabled.
  *
  * @param ResourceControllerEvent $event
  */
 public function onChannelPreDelete(ResourceControllerEvent $event)
 {
     $channel = $event->getSubject();
     if (!$channel instanceof ChannelInterface) {
         throw new UnexpectedTypeException($channel, ChannelInterface::class);
     }
     $results = $this->channelRepository->findBy(array('enabled' => true));
     if (!$results || count($results) === 1 && current($results) === $channel) {
         $event->stop('error.at_least_one');
     }
 }
 /**
  * Prevent channel deletion if no more channels enabled.
  *
  * @param ResourceControllerEvent $event
  */
 public function onChannelPreDelete(ResourceControllerEvent $event)
 {
     $channel = $event->getSubject();
     if (!$channel instanceof ChannelInterface) {
         throw new UnexpectedTypeException($channel, ChannelInterface::class);
     }
     $results = $this->channelRepository->findBy(['enabled' => true]);
     if (!$results || count($results) === 1 && current($results) === $channel) {
         $event->stop('sylius.ui.the_channel_cannot_be_deleted_at_least_one_enabled_channel_is_required');
     }
 }
示例#3
0
 public function pagePreDelete(ResourceControllerEvent $event)
 {
     /* @var $page PageInterface */
     $page = $event->getSubject();
     /*
      * Don't allow deletion of homepage / root
      */
     if ($page->getHomepage() || $page->getRoot()) {
         $event->stop('symedit.page.root_or_home');
     }
 }
 /**
  * Hook into the Wishlist's pre-remove event,
  * prevent removal if this is the only wishlist for the customer.
  *
  * @param ResourceControllerEvent $event
  */
 public function preRemove(ResourceControllerEvent $event)
 {
     /** @var WishlistInterface $wishlist */
     $wishlist = $event->getSubject();
     /** @var WishlistRepositoryInterface $wishlistRepository */
     $wishlistRepository = $this->container->get('webburza.repository.wishlist');
     // Get the number of wishlists for the customer
     $wishlistCount = $wishlistRepository->getCountForCustomer($wishlist->getCustomer());
     // If this is the only wishlist for the customer, stop the event
     if ($wishlistCount == 1) {
         $event->stop('webburza.sylius.wishlist.cannot_delete', ResourceControllerEvent::TYPE_ERROR, [], 400);
     }
 }