vendor/gourmops/product-short-description/src/GourmopsProductShortDescription.php line 21

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