custom/plugins/NetiNextCmsElementBuilder/src/NetiNextCmsElementBuilder.php line 17

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace NetInventors\NetiNextCmsElementBuilder;
  4. use Doctrine\DBAL\Exception;
  5. use Shopware\Core\Content\Cms\DataResolver\CmsSlotsDataResolver;
  6. use Shopware\Core\Framework\Parameter\AdditionalBundleParameters;
  7. use Shopware\Core\Framework\Plugin;
  8. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  9. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  10. use NetInventors\NetiNextCmsElementBuilder\Components\Setup;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\Reference;
  13. class NetiNextCmsElementBuilder extends Plugin
  14. {
  15.     private bool $autoloaderInjected false;
  16.     public function getAdditionalBundles(AdditionalBundleParameters $parameters): array
  17.     {
  18.         // This is not a nice solution, but there is no other way to inject the autoloader
  19.         if (!$this->autoloaderInjected) {
  20.             $this->injectAutoloader();
  21.             $this->autoloaderInjected true;
  22.         }
  23.         return parent::getAdditionalBundles($parameters);
  24.     }
  25.     /**
  26.      * @throws \Exception
  27.      */
  28.     public function install(InstallContext $installContext): void
  29.     {
  30.         parent::install($installContext);
  31.         (new Setup($installContext$this->container))->install();
  32.     }
  33.     /**
  34.      * @throws Exception
  35.      * @throws \Exception
  36.      */
  37.     public function uninstall(UninstallContext $uninstallContext): void
  38.     {
  39.         parent::uninstall($uninstallContext);
  40.         if ($uninstallContext->keepUserData()) {
  41.             return;
  42.         }
  43.         (new Setup($uninstallContext$this->container))->uninstall();
  44.     }
  45.     public function build(ContainerBuilder $container): void
  46.     {
  47.         parent::build($container);
  48.         $container->getDefinition(CmsSlotsDataResolver::class)
  49.             ->setArgument(0, new Reference('net_inventors.cms_element_builder.resolver.elements'));
  50.     }
  51.     private function injectAutoloader(): void
  52.     {
  53.         // For development
  54.         if (is_file(__DIR__ '/Resources/build/vendor/autoload.php')) {
  55.             require __DIR__ '/Resources/build/vendor/autoload.php';
  56.             return;
  57.         }
  58.         // For production
  59.         if (is_file(__DIR__ '/Resources/vendor/autoload.php')) {
  60.             require __DIR__ '/Resources/vendor/autoload.php';
  61.             return;
  62.         }
  63.     }
  64. }