<?php declare(strict_types=1);
/**
* GourmopsProductShortDescription
* Copyright (c) Simone Gottwald GOURMOPS
*/
namespace GourmopsProductShortDescription;
use GourmopsProductShortDescription\Util\Lifecycle\InstallUninstall;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
/**
* Class GourmopsProductShortDescription
*/
class GourmopsProductShortDescription extends Plugin
{
public const CUSTOM_FIELD_SET_NAME = 'custom_gourmops_product_short_description';
public const CUSTOM_FIELD_SHORT_DESCRIPTION = self::CUSTOM_FIELD_SET_NAME . '_short_description';
public const FIELD_PLACEHOLDER = 'gourmops_product_short_description';
/**
* @param InstallContext $installContext
*
* @throws NotFoundExceptionInterface
* @throws ContainerExceptionInterface
*
* @return void
*/
public function install(InstallContext $installContext): void
{
(new InstallUninstall($this->getCustomSetFieldRepository(), $installContext->getContext()))
->install();
}
/**
* @param UninstallContext $uninstallContext
*
* @throws NotFoundExceptionInterface
* @throws ContainerExceptionInterface
*
* @return void
*/
public function uninstall(UninstallContext $uninstallContext): void
{
if ($uninstallContext->keepUserData()) {
return;
}
(new InstallUninstall($this->getCustomSetFieldRepository(), $uninstallContext->getContext()))
->uninstall();
}
/**
* @return ContainerInterface
*/
protected function getContainer(): ContainerInterface
{
return $this->container;
}
/**
* @throws NotFoundExceptionInterface
* @throws ContainerExceptionInterface
*
* @return EntityRepositoryInterface
*/
protected function getCustomSetFieldRepository(): EntityRepositoryInterface
{
return $this->getContainer()->get('custom_field_set.repository');
}
}