src/Sylius/Bundle/CoreBundle/EventListener/ChannelDeletionListener.php
public function onChannelPreDelete(ResourceControllerEvent $event): void
    {
        $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.channel.delete_error');
        }
    }
public function onChannelPreDelete(ResourceControllerEvent $event): void
    {
        $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.channel.delete_error');
        }
    }
public function onChannelPreDelete ( ResourceControllerEvent $ event ) : void { $ 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.channel.delete_error' ) ; } }
Prevent channel deletion if no more channels enabled.
Prevent channel deletion if no more channels enabled .