/** * 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'); } }