<?php declare(strict_types=1);
/**
* GourmopsProductBenefits
* Copyright (c) Simone Gottwald GOURMOPS
*/
namespace GourmopsProductBenefits;
use GourmopsProductBenefits\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 GourmopsProductBenefits
*/
class GourmopsProductBenefits extends Plugin
{
public const CUSTOM_FIELD_SET_NAME = 'custom_gourmops_product_benefits';
public const CUSTOM_FIELD_FIRST_BENEFIT_IMAGE = self::CUSTOM_FIELD_SET_NAME . '_first_benefit_image';
public const CUSTOM_FIELD_FIRST_BENEFIT_DESCRIPTION = self::CUSTOM_FIELD_SET_NAME . '_first_benefit_description';
public const CUSTOM_FIELD_SECOND_BENEFIT_IMAGE = self::CUSTOM_FIELD_SET_NAME . '_second_benefit_image';
public const CUSTOM_FIELD_SECOND_BENEFIT_DESCRIPTION = self::CUSTOM_FIELD_SET_NAME . '_second_benefit_description';
public const CUSTOM_FIELD_THIRD_BENEFIT_IMAGE = self::CUSTOM_FIELD_SET_NAME . '_third_benefit_image';
public const CUSTOM_FIELD_THIRD_BENEFIT_DESCRIPTION = self::CUSTOM_FIELD_SET_NAME . '_third_benefit_description';
public const CUSTOM_FIELD_FOURTH_BENEFIT_IMAGE = self::CUSTOM_FIELD_SET_NAME . '_fourth_benefit_image';
public const CUSTOM_FIELD_FOURTH_BENEFIT_DESCRIPTION = self::CUSTOM_FIELD_SET_NAME . '_fourth_benefit_description';
public const CUSTOM_FIELD_FIFTH_BENEFIT_IMAGE = self::CUSTOM_FIELD_SET_NAME . '_fifth_benefit_image';
public const CUSTOM_FIELD_FIFTH_BENEFIT_DESCRIPTION = self::CUSTOM_FIELD_SET_NAME . '_fifth_benefit_description';
public const CUSTOM_FIELD_SIXTH_BENEFIT_IMAGE = self::CUSTOM_FIELD_SET_NAME . '_sixth_benefit_image';
public const CUSTOM_FIELD_SIXTH_BENEFIT_DESCRIPTION = self::CUSTOM_FIELD_SET_NAME . '_sixth_benefit_description';
public const FIELD_PLACEHOLDER = 'gourmops_product_benefits';
/**
* @param InstallContext $installContext
*
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*
* @return void
*/
public function install(InstallContext $installContext): void
{
(new InstallUninstall($this->getCustomSetFieldRepository(), $installContext->getContext()))
->install();
}
/**
* @param UninstallContext $uninstallContext
*
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*
* @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 ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*
* @return EntityRepositoryInterface
*/
protected function getCustomSetFieldRepository(): EntityRepositoryInterface
{
return $this->getContainer()->get('custom_field_set.repository');
}
}