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\EntityRepositoryInterface;
  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.     public function enrichPrivileges(): array
  71.     {
  72.         return [
  73.             'cms.viewer' => [
  74.                 self::SWAG_CMS_EXTENSIONS_QUICKVIEW_PRIVILEGE_KEY 'read',
  75.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PRIVILEGE_KEY 'read',
  76.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PAGE_SETTINGS_PRIVILEGE_KEY 'read',
  77.             ],
  78.             'cms.editor' => [
  79.                 self::SWAG_CMS_EXTENSIONS_QUICKVIEW_PRIVILEGE_KEY 'update',
  80.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PRIVILEGE_KEY 'update',
  81.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PAGE_SETTINGS_PRIVILEGE_KEY 'update',
  82.             ],
  83.             'cms.creator' => [
  84.                 self::SWAG_CMS_EXTENSIONS_QUICKVIEW_PRIVILEGE_KEY 'create',
  85.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PRIVILEGE_KEY 'create',
  86.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PAGE_SETTINGS_PRIVILEGE_KEY 'create',
  87.             ],
  88.             'cms.deleter' => [
  89.                 self::SWAG_CMS_EXTENSIONS_QUICKVIEW_PRIVILEGE_KEY 'delete',
  90.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PRIVILEGE_KEY 'delete',
  91.                 self::SWAG_CMS_EXTENSIONS_SCROLL_NAVIGATION_PAGE_SETTINGS_PRIVILEGE_KEY 'delete',
  92.             ],
  93.         ];
  94.     }
  95.     private function getFormDefaults(): FormDefaults
  96.     {
  97.         /** @var EntityRepositoryInterface $mailTemplateRepository */
  98.         $mailTemplateRepository $this->container->get(\sprintf('%s.repository'MailTemplateDefinition::ENTITY_NAME));
  99.         /** @var EntityRepositoryInterface $mailTemplateTypeRepository */
  100.         $mailTemplateTypeRepository $this->container->get(\sprintf('%s.repository'MailTemplateTypeDefinition::ENTITY_NAME));
  101.         $formDefaults = new FormDefaults($mailTemplateRepository$mailTemplateTypeRepository);
  102.         return $formDefaults;
  103.     }
  104. }