custom/plugins/SwagCmsExtensions/src/SwagCmsExtensions.php line 26

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /*
  3.  * (c) shopware AG <info@shopware.com>
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Swag\CmsExtensions;
  8. use Doctrine\DBAL\Connection;
  9. use Shopware\Core\Content\MailTemplate\Aggregate\MailTemplateType\MailTemplateTypeDefinition;
  10. use Shopware\Core\Content\MailTemplate\MailTemplateDefinition;
  11. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  12. use Shopware\Core\Framework\Plugin;
  13. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  14. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  15. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  16. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  17. use Swag\CmsExtensions\Util\Feature\SwagCmsExtensionsFeatureUtil;
  18. use Swag\CmsExtensions\Util\Lifecycle\FormDefaults;
  19. use Swag\CmsExtensions\Util\Lifecycle\Uninstaller;
  20. use Symfony\Component\Config\FileLocator;
  21. use Symfony\Component\DependencyInjection\ContainerBuilder;
  22. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  23. class SwagCmsExtensions extends Plugin
  24. {
  25.     private const SWAG_CMS_EXTENSIONS_QUICKVIEW_PRIVILEGE_KEY 'swag_cms_extensions_quickview:';
  26.     private const SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PRIVILEGE_KEY 'swag_cms_extensions_scroll_navigation:';
  27.     private const SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PAGE_SETTINGS_PRIVILEGE_KEY 'swag_cms_extensions_scroll_navigation_page_settings:';
  28.     public function build(ContainerBuilder $container): void
  29.     {
  30.         parent::build($container);
  31.         $featureUtil = new SwagCmsExtensionsFeatureUtil();
  32.         $featureUtil->registerFeatures();
  33.         $featureLoader = new XmlFileLoader($container, new FileLocator($this->getPath() . '/Resources/config/Features/'));
  34.         $featureLoader->load('form_builder.xml');
  35.         $featureLoader->load('quickview.xml');
  36.         $featureLoader->load('block_rule.xml');
  37.         $featureLoader->load('scroll_navigation.xml');
  38.     }
  39.     public function boot(): void
  40.     {
  41.         parent::boot();
  42.         $featureUtil = new SwagCmsExtensionsFeatureUtil();
  43.         $featureUtil->registerFeatures();
  44.     }
  45.     public function uninstall(UninstallContext $uninstallContext): void
  46.     {
  47.         parent::uninstall($uninstallContext);
  48.         /** @var Connection $connection */
  49.         $connection $this->container->get(Connection::class);
  50.         (new Uninstaller(
  51.             $uninstallContext,
  52.             $connection
  53.         ))->uninstall();
  54.     }
  55.     public function update(UpdateContext $updateContext): void
  56.     {
  57.         parent::update($updateContext);
  58.         $this->getFormDefaults()->update($updateContext);
  59.     }
  60.     public function activate(ActivateContext $activateContext): void
  61.     {
  62.         parent::activate($activateContext);
  63.         $this->getFormDefaults()->activate($activateContext->getContext());
  64.     }
  65.     public function deactivate(DeactivateContext $deactivateContext): void
  66.     {
  67.         parent::deactivate($deactivateContext);
  68.         $this->getFormDefaults()->deactivate($deactivateContext->getContext());
  69.     }
  70.     /**
  71.      * @return array<string, array<int, string>>
  72.      */
  73.     public function enrichPrivileges(): array
  74.     {
  75.         return [
  76.             'cms.viewer' => [
  77.                 self::SWAG_CMS_EXTENSIONS_QUICKVIEW_PRIVILEGE_KEY 'read',
  78.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PRIVILEGE_KEY 'read',
  79.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PAGE_SETTINGS_PRIVILEGE_KEY 'read',
  80.             ],
  81.             'cms.editor' => [
  82.                 self::SWAG_CMS_EXTENSIONS_QUICKVIEW_PRIVILEGE_KEY 'update',
  83.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PRIVILEGE_KEY 'update',
  84.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PAGE_SETTINGS_PRIVILEGE_KEY 'update',
  85.             ],
  86.             'cms.creator' => [
  87.                 self::SWAG_CMS_EXTENSIONS_QUICKVIEW_PRIVILEGE_KEY 'create',
  88.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PRIVILEGE_KEY 'create',
  89.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PAGE_SETTINGS_PRIVILEGE_KEY 'create',
  90.             ],
  91.             'cms.deleter' => [
  92.                 self::SWAG_CMS_EXTENSIONS_QUICKVIEW_PRIVILEGE_KEY 'delete',
  93.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PRIVILEGE_KEY 'delete',
  94.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PAGE_SETTINGS_PRIVILEGE_KEY 'delete',
  95.             ],
  96.         ];
  97.     }
  98.     private function getFormDefaults(): FormDefaults
  99.     {
  100.         /** @var EntityRepository $mailTemplateRepository */
  101.         $mailTemplateRepository $this->container->get(\sprintf('%s.repository'MailTemplateDefinition::ENTITY_NAME));
  102.         /** @var EntityRepository $mailTemplateTypeRepository */
  103.         $mailTemplateTypeRepository $this->container->get(\sprintf('%s.repository'MailTemplateTypeDefinition::ENTITY_NAME));
  104.         return new FormDefaults($mailTemplateRepository$mailTemplateTypeRepository);
  105.     }
  106. }