vendor/gourmops/product-ingredients/src/GourmopsProductIngredients.php line 21

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * GourmopsProduct
  4.  * Copyright (c) Simone Gottwald GOURMOPS
  5.  */
  6. namespace GourmopsProductIngredients;
  7. use GourmopsProductIngredients\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 GourmopsProductIngredients
  17.  */
  18. class GourmopsProductIngredients extends Plugin
  19. {
  20.     public const CUSTOM_FIELD_SET_NAME 'custom_gourmops_product_ingredients';
  21.     public const CUSTOM_FIELD_FIRST_INGREDIENT_IMAGE self::CUSTOM_FIELD_SET_NAME '_first_ingredient_image';
  22.     public const CUSTOM_FIELD_FIRST_INGREDIENT_DESCRIPTION self::CUSTOM_FIELD_SET_NAME '_first_ingredient_description';
  23.     public const CUSTOM_FIELD_SECOND_INGREDIENT_IMAGE self::CUSTOM_FIELD_SET_NAME '_second_ingredient_image';
  24.     public const CUSTOM_FIELD_SECOND_INGREDIENT_DESCRIPTION self::CUSTOM_FIELD_SET_NAME '_second_ingredient_description';
  25.     public const CUSTOM_FIELD_THIRD_INGREDIENT_IMAGE self::CUSTOM_FIELD_SET_NAME '_third_ingredient_image';
  26.     public const CUSTOM_FIELD_THIRD_INGREDIENT_DESCRIPTION self::CUSTOM_FIELD_SET_NAME '_third_ingredient_description';
  27.     public const CUSTOM_FIELD_FOURTH_INGREDIENT_IMAGE self::CUSTOM_FIELD_SET_NAME '_fourth_ingredient_image';
  28.     public const CUSTOM_FIELD_FOURTH_INGREDIENT_DESCRIPTION self::CUSTOM_FIELD_SET_NAME '_fourth_ingredient_description';
  29.     public const FIELD_PLACEHOLDER 'gourmops_product_ingredients';
  30.     /**
  31.      * @param InstallContext $installContext
  32.      *
  33.      * @throws ContainerExceptionInterface
  34.      * @throws NotFoundExceptionInterface
  35.      *
  36.      * @return void
  37.      */
  38.     public function install(InstallContext $installContext): void
  39.     {
  40.         (new InstallUninstall($this->getCustomSetFieldRepository(), $installContext->getContext()))
  41.             ->install();
  42.     }
  43.     /**
  44.      * @param UninstallContext $uninstallContext
  45.      *
  46.      * @throws ContainerExceptionInterface
  47.      * @throws NotFoundExceptionInterface
  48.      *
  49.      * @return void
  50.      */
  51.     public function uninstall(UninstallContext $uninstallContext): void
  52.     {
  53.         if ($uninstallContext->keepUserData()) {
  54.             return;
  55.         }
  56.         (new InstallUninstall($this->getCustomSetFieldRepository(), $uninstallContext->getContext()))
  57.             ->uninstall();
  58.     }
  59.     /**
  60.      * @return ContainerInterface
  61.      */
  62.     protected function getContainer(): ContainerInterface
  63.     {
  64.         return $this->container;
  65.     }
  66.     /**
  67.      * @throws ContainerExceptionInterface
  68.      * @throws NotFoundExceptionInterface
  69.      *
  70.      * @return EntityRepositoryInterface
  71.      */
  72.     protected function getCustomSetFieldRepository(): EntityRepositoryInterface
  73.     {
  74.         return $this->getContainer()->get('custom_field_set.repository');
  75.     }
  76. }