vendor/gourmops/product-benefits/src/GourmopsProductBenefits.php line 21

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * GourmopsProductBenefits
  4.  * Copyright (c) Simone Gottwald GOURMOPS
  5.  */
  6. namespace GourmopsProductBenefits;
  7. use GourmopsProductBenefits\Util\Lifecycle\InstallUninstall;
  8. use Psr\Container\ContainerExceptionInterface;
  9. use Psr\Container\ContainerInterface;
  10. use Psr\Container\NotFoundExceptionInterface;
  11. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  12. use Shopware\Core\Framework\Plugin;
  13. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  14. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  15. /**
  16.  * Class GourmopsProductBenefits
  17.  */
  18. class GourmopsProductBenefits extends Plugin
  19. {
  20.     public const CUSTOM_FIELD_SET_NAME 'custom_gourmops_product_benefits';
  21.     public const CUSTOM_FIELD_FIRST_BENEFIT_IMAGE self::CUSTOM_FIELD_SET_NAME '_first_benefit_image';
  22.     public const CUSTOM_FIELD_FIRST_BENEFIT_DESCRIPTION self::CUSTOM_FIELD_SET_NAME '_first_benefit_description';
  23.     public const CUSTOM_FIELD_SECOND_BENEFIT_IMAGE self::CUSTOM_FIELD_SET_NAME '_second_benefit_image';
  24.     public const CUSTOM_FIELD_SECOND_BENEFIT_DESCRIPTION self::CUSTOM_FIELD_SET_NAME '_second_benefit_description';
  25.     public const CUSTOM_FIELD_THIRD_BENEFIT_IMAGE self::CUSTOM_FIELD_SET_NAME '_third_benefit_image';
  26.     public const CUSTOM_FIELD_THIRD_BENEFIT_DESCRIPTION self::CUSTOM_FIELD_SET_NAME '_third_benefit_description';
  27.     public const CUSTOM_FIELD_FOURTH_BENEFIT_IMAGE self::CUSTOM_FIELD_SET_NAME '_fourth_benefit_image';
  28.     public const CUSTOM_FIELD_FOURTH_BENEFIT_DESCRIPTION self::CUSTOM_FIELD_SET_NAME '_fourth_benefit_description';
  29.     public const CUSTOM_FIELD_FIFTH_BENEFIT_IMAGE self::CUSTOM_FIELD_SET_NAME '_fifth_benefit_image';
  30.     public const CUSTOM_FIELD_FIFTH_BENEFIT_DESCRIPTION self::CUSTOM_FIELD_SET_NAME '_fifth_benefit_description';
  31.     public const CUSTOM_FIELD_SIXTH_BENEFIT_IMAGE self::CUSTOM_FIELD_SET_NAME '_sixth_benefit_image';
  32.     public const CUSTOM_FIELD_SIXTH_BENEFIT_DESCRIPTION self::CUSTOM_FIELD_SET_NAME '_sixth_benefit_description';
  33.     public const FIELD_PLACEHOLDER 'gourmops_product_benefits';
  34.     /**
  35.      * @param InstallContext $installContext
  36.      *
  37.      * @throws ContainerExceptionInterface
  38.      * @throws NotFoundExceptionInterface
  39.      *
  40.      * @return void
  41.      */
  42.     public function install(InstallContext $installContext): void
  43.     {
  44.         (new InstallUninstall($this->getCustomSetFieldRepository(), $installContext->getContext()))
  45.             ->install();
  46.     }
  47.     /**
  48.      * @param UninstallContext $uninstallContext
  49.      *
  50.      * @throws ContainerExceptionInterface
  51.      * @throws NotFoundExceptionInterface
  52.      *
  53.      * @return void
  54.      */
  55.     public function uninstall(UninstallContext $uninstallContext): void
  56.     {
  57.         if ($uninstallContext->keepUserData()) {
  58.             return;
  59.         }
  60.         (new InstallUninstall($this->getCustomSetFieldRepository(), $uninstallContext->getContext()))
  61.             ->uninstall();
  62.     }
  63.     /**
  64.      * @return ContainerInterface
  65.      */
  66.     protected function getContainer(): ContainerInterface
  67.     {
  68.         return $this->container;
  69.     }
  70.     /**
  71.      * @throws ContainerExceptionInterface
  72.      * @throws NotFoundExceptionInterface
  73.      *
  74.      * @return EntityRepositoryInterface
  75.      */
  76.     protected function getCustomSetFieldRepository(): EntityRepositoryInterface
  77.     {
  78.         return $this->getContainer()->get('custom_field_set.repository');
  79.     }
  80. }