custom/plugins/MoorlProductVideo/src/MoorlProductVideo.php line 13

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Moorl\ProductVideo;
  3. use MoorlFoundation\Core\PluginFoundation;
  4. use Shopware\Core\Framework\Context;
  5. use Shopware\Core\Framework\Plugin;
  6. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  7. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  9. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  10. class MoorlProductVideo extends Plugin
  11. {
  12.     private function refreshPluginData(Context $context$justDelete null): void
  13.     {
  14.         /* @var $foundation PluginFoundation */
  15.         $foundation $this->container->get(PluginFoundation::class);
  16.         $foundation->setContext($context);
  17.         if ($justDelete) {
  18.             $foundation->removeCustomFields('moorl_video');
  19.             $foundation->removeCmsSlots(['moorl_form_builder']);
  20.             $foundation->removeCmsBlocks(['moorl_form_builder']);
  21.             return;
  22.         }
  23.         $data = [[
  24.             'name' => 'moorl_video',
  25.             'config' => [
  26.                 'label' => [
  27.                     'en-GB' => 'Product video',
  28.                     'de-DE' => 'Produktvideo',
  29.                 ],
  30.             ],
  31.             'relations' => [['entityName' => 'media']],
  32.             'customFields' => [
  33.                 [
  34.                     'name' => 'moorl_video_src',
  35.                     'type' => 'text',
  36.                     'config' => [
  37.                         'componentName' => 'sw-field',
  38.                         'customFieldType' => 'text',
  39.                         'customFieldPosition' => 1,
  40.                         'label' => [
  41.                             'en-GB' => 'URL to video',
  42.                             'de-DE' => 'URL zum Video',
  43.                         ],
  44.                         'placeholder' => [
  45.                             'en-GB' => 'https://www.youtube.com/watch?v=AnyID',
  46.                             'de-DE' => 'https://www.youtube.com/watch?v=IrgendeineID',
  47.                         ],
  48.                     ]
  49.                 ],
  50.                 [
  51.                     'name' => 'moorl_video_bg',
  52.                     'type' => 'colorpicker',
  53.                     'config' => [
  54.                         'componentName' => 'sw-field',
  55.                         'customFieldType' => 'colorpicker',
  56.                         'customFieldPosition' => 2,
  57.                         'label' => [
  58.                             'en-GB' => 'Background color',
  59.                             'de-DE' => 'Hintergundfarbe',
  60.                         ],
  61.                     ]
  62.                 ],
  63.                 [
  64.                     'name' => 'moorl_video_cover',
  65.                     'type' => 'media',
  66.                     'config' => [
  67.                         'componentName' => 'sw-media-field',
  68.                         'customFieldType' => 'media',
  69.                         'customFieldPosition' => 3,
  70.                         'label' => [
  71.                             'en-GB' => 'Cover',
  72.                             'de-DE' => 'Cover',
  73.                         ],
  74.                     ]
  75.                 ],
  76.             ]
  77.         ]];
  78.         $foundation->updateCustomFields($data'moorl_video');
  79.     }
  80.     public function activate(ActivateContext $activateContext): void
  81.     {
  82.         parent::activate($activateContext);
  83.         $this->refreshPluginData($activateContext->getContext());
  84.     }
  85.     public function install(InstallContext $installContext): void
  86.     {
  87.         parent::install($installContext);
  88.         $this->refreshPluginData($installContext->getContext());
  89.     }
  90.     public function update(UpdateContext $updateContext): void
  91.     {
  92.         parent::update($updateContext);
  93.         $this->refreshPluginData($updateContext->getContext());
  94.     }
  95.     public function uninstall(UninstallContext $uninstallContext): void
  96.     {
  97.         parent::uninstall($uninstallContext);
  98.         if ($uninstallContext->keepUserData()) {
  99.             return;
  100.         }
  101.         $this->refreshPluginData($uninstallContext->getContext(), true);
  102.     }
  103. }