custom/plugins/CogiMediaDescription/src/CogiMediaDescription.php line 12

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Cogi\CogiMediaDescription;
  3. use Cogi\CogiMediaDescription\Utils\CustomFieldWizard;
  4. use Shopware\Core\Framework\Context;
  5. use Shopware\Core\Framework\Plugin;
  6. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  7. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  9. class CogiMediaDescription extends Plugin {
  10.     const CUSTOM_FIELD_SET_NAME 'cogiMediaDescriptionPRODUCT';
  11.     const CUSTOM_FIELD_SET_NAME_MEDIA 'cogiMediaDescriptionMEDIA';
  12.     public function install(InstallContext $context): void {
  13.         parent::install($context);
  14.         $this->installCustomFields($context->getContext());
  15.     }
  16.     /**
  17.      * @param UninstallContext $context
  18.      */
  19.     public function uninstall(UninstallContext $context): void {
  20.         if ($context->keepUserData()) {
  21.             return;
  22.         }
  23.         try {
  24.             $customFieldWizard = new CustomFieldWizard(self::CUSTOM_FIELD_SET_NAME$this->container$context->getContext());
  25.             $customFieldWizard->uninstall();
  26.         } catch (\Exception $e) {
  27.             // Something went wrong
  28.         }
  29.         try {
  30.             $customFieldWizard = new CustomFieldWizard(self::CUSTOM_FIELD_SET_NAME_MEDIA$this->container$context->getContext());
  31.             $customFieldWizard->uninstall();
  32.         } catch (\Exception $e) {
  33.             // Something went wrong
  34.         }
  35.         parent::uninstall($context);
  36.     }
  37.     /**
  38.      * @param UpdateContext $updateContext
  39.      */
  40.     public function update(UpdateContext $updateContext): void {
  41.         parent::update($updateContext);
  42.         $this->installCustomFields($updateContext->getContext());
  43.     }
  44.     protected function installCustomFields(Context $context) {
  45.         try {
  46.             $customFieldWizard = new CustomFieldWizard(self::CUSTOM_FIELD_SET_NAME$this->container$context);
  47.             $customFieldWizard->addFieldSet('product_media', [
  48.                         'de-DE' => 'Beschreibung für Produktbilder''en-GB' => 'Description for product images'
  49.                     ], ['product_media'])->addField('product_media''caption''html', [
  50.                         'de-DE' => 'Beschreibung''en-GB' => 'Caption'
  51.                     ], [], 'sw-text-editor''textEditor')->install();
  52.         } catch (\Exception $e) {
  53.             // Something went wrong
  54.         }
  55.         try {
  56.             $customFieldWizard = new CustomFieldWizard(self::CUSTOM_FIELD_SET_NAME_MEDIA$this->container$context);
  57.             $customFieldWizard->addFieldSet('media', [
  58.                 'de-DE' => 'Beschreibung für Bilder''en-GB' => 'Description for images'
  59.             ], ['media'])->addField('media''caption''html', [
  60.                 'de-DE' => 'Beschreibung''en-GB' => 'Caption'
  61.             ], [], 'sw-text-editor''textEditor')->install();
  62.         } catch (\Exception $e) {
  63.             // Something went wrong
  64.         }
  65.     }
  66. }