<?php declare(strict_types=1);
/**
* GourmopsProduct
* Copyright (c) Simone Gottwald GOURMOPS
*/
namespace GourmopsProductIngredients;
use GourmopsProductIngredients\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 GourmopsProductIngredients
*/
class GourmopsProductIngredients extends Plugin
{
public const CUSTOM_FIELD_SET_NAME = 'custom_gourmops_product_ingredients';
public const CUSTOM_FIELD_FIRST_INGREDIENT_IMAGE = self::CUSTOM_FIELD_SET_NAME . '_first_ingredient_image';
public const CUSTOM_FIELD_FIRST_INGREDIENT_DESCRIPTION = self::CUSTOM_FIELD_SET_NAME . '_first_ingredient_description';
public const CUSTOM_FIELD_SECOND_INGREDIENT_IMAGE = self::CUSTOM_FIELD_SET_NAME . '_second_ingredient_image';
public const CUSTOM_FIELD_SECOND_INGREDIENT_DESCRIPTION = self::CUSTOM_FIELD_SET_NAME . '_second_ingredient_description';
public const CUSTOM_FIELD_THIRD_INGREDIENT_IMAGE = self::CUSTOM_FIELD_SET_NAME . '_third_ingredient_image';
public const CUSTOM_FIELD_THIRD_INGREDIENT_DESCRIPTION = self::CUSTOM_FIELD_SET_NAME . '_third_ingredient_description';
public const CUSTOM_FIELD_FOURTH_INGREDIENT_IMAGE = self::CUSTOM_FIELD_SET_NAME . '_fourth_ingredient_image';
public const CUSTOM_FIELD_FOURTH_INGREDIENT_DESCRIPTION = self::CUSTOM_FIELD_SET_NAME . '_fourth_ingredient_description';
public const FIELD_PLACEHOLDER = 'gourmops_product_ingredients';
/**
* @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');
}
}