custom/plugins/CMSCollection/src/CMSCollection.php line 10

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace TigerMedia\General\CMSCollection;
  3. use Shopware\Core\Framework\Plugin;
  4. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  5. use Shopware\Core\Framework\Uuid\Uuid;
  6. use Shopware\Core\System\CustomField\CustomFieldTypes;
  7. class CMSCollection extends Plugin
  8. {
  9.     public function activate(ActivateContext $activateContext): void
  10.     {
  11.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  12.         $this->installCustomFieldsForManufacturers($activateContext$customFieldSetRepository);
  13.         parent::activate($activateContext);
  14.     }
  15.     private function installCustomFieldsForManufacturers(ActivateContext $context, ?object $customFieldSetRepository): void
  16.     {
  17.         $connection $this->container->get('Doctrine\DBAL\Connection');
  18.         $customFieldSetRepository->upsert([[
  19.             'id' => Uuid::fromStringToHex('Tiger Brands Listing'),
  20.             'name' => 'tiger_brands',
  21.             'active' => true,
  22.             'config' => [
  23.                 'label' => [
  24.                     'en-GB' => 'Tiger Brands Settings'
  25.                 ],
  26.             ],
  27.             'customFields' => $this->getCustomFields(),
  28.             'relations' => [
  29.                 [
  30.                     'id' => Uuid::fromStringToHex('tigerbrandmanufacturer'),
  31.                     'entityName' => 'product_manufacturer'
  32.                 ]
  33.             ]
  34.         ]], $context->getContext());
  35.     }
  36.     private function getCustomFields(): array
  37.     {
  38.         return [
  39.             [
  40.                 'id' => Uuid::fromStringToHex('displaybrands'),
  41.                 'name' => 'displaybrands',
  42.                 'type' => CustomFieldTypes::BOOL,
  43.                 'config' => [
  44.                     'type' => 'checkbox',
  45.                     'componentName' => 'sw-field',
  46.                     'bordered' => false,
  47.                     'label' => [
  48.                         'en-GB' => 'Display in Storefront'
  49.                     ],
  50.                     'customFieldPosition' => 0,
  51.                     'helpText' => [
  52.                         'en-GB' => 'Displays specific brand in Storefront'
  53.                     ]
  54.                 ]
  55.             ]
  56.         ];
  57.     }
  58. }