<?php declare(strict_types=1);
namespace Cogi\CogiMediaDescription;
use Cogi\CogiMediaDescription\Utils\CustomFieldWizard;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
class CogiMediaDescription extends Plugin {
const CUSTOM_FIELD_SET_NAME = 'cogiMediaDescriptionPRODUCT';
const CUSTOM_FIELD_SET_NAME_MEDIA = 'cogiMediaDescriptionMEDIA';
public function install(InstallContext $context): void {
parent::install($context);
$this->installCustomFields($context->getContext());
}
/**
* @param UninstallContext $context
*/
public function uninstall(UninstallContext $context): void {
if ($context->keepUserData()) {
return;
}
try {
$customFieldWizard = new CustomFieldWizard(self::CUSTOM_FIELD_SET_NAME, $this->container, $context->getContext());
$customFieldWizard->uninstall();
} catch (\Exception $e) {
// Something went wrong
}
try {
$customFieldWizard = new CustomFieldWizard(self::CUSTOM_FIELD_SET_NAME_MEDIA, $this->container, $context->getContext());
$customFieldWizard->uninstall();
} catch (\Exception $e) {
// Something went wrong
}
parent::uninstall($context);
}
/**
* @param UpdateContext $updateContext
*/
public function update(UpdateContext $updateContext): void {
parent::update($updateContext);
$this->installCustomFields($updateContext->getContext());
}
protected function installCustomFields(Context $context) {
try {
$customFieldWizard = new CustomFieldWizard(self::CUSTOM_FIELD_SET_NAME, $this->container, $context);
$customFieldWizard->addFieldSet('product_media', [
'de-DE' => 'Beschreibung für Produktbilder', 'en-GB' => 'Description for product images'
], ['product_media'])->addField('product_media', 'caption', 'html', [
'de-DE' => 'Beschreibung', 'en-GB' => 'Caption'
], [], 'sw-text-editor', 'textEditor')->install();
} catch (\Exception $e) {
// Something went wrong
}
try {
$customFieldWizard = new CustomFieldWizard(self::CUSTOM_FIELD_SET_NAME_MEDIA, $this->container, $context);
$customFieldWizard->addFieldSet('media', [
'de-DE' => 'Beschreibung für Bilder', 'en-GB' => 'Description for images'
], ['media'])->addField('media', 'caption', 'html', [
'de-DE' => 'Beschreibung', 'en-GB' => 'Caption'
], [], 'sw-text-editor', 'textEditor')->install();
} catch (\Exception $e) {
// Something went wrong
}
}
}