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

Open in your IDE?
  1. <?php
  2. namespace Six\CategorySeoText;
  3. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  4. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  5. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  6. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  7. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  8. use Shopware\Core\Framework\Context;
  9. use Shopware\Core\Framework\Plugin;
  10. class SixCategorySeoText extends Plugin
  11. {
  12.     public const FIELDSET_ID_CATEGORY '9f4fed9b63e142d1acbd039a093794c1';
  13.             
  14.     public function setupCustomFields(Context $context): void {
  15.         /** @var EntityRepositoryInterface $customFieldSetRepository */
  16.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  17.         
  18.         $customFieldSetCategory = [
  19.             'id' => self::FIELDSET_ID_CATEGORY,
  20.             'name' => 'six_seo_text_category',
  21.             'config' => [
  22.                 'label' => [
  23.                     'en-GB' => 'SEO Text (sixmedia)',
  24.                     'de-DE' => 'SEO Text (sixmedia)',
  25.                 ],
  26.                 'translated' => 'true'                    
  27.             ],            
  28.             'active' => boolval(1)
  29.         ];
  30.         $customFieldSetRepository->upsert([$customFieldSetCategory], $context);
  31.         
  32.         /** @var EntityRepositoryInterface $customFieldSetRelationRepository */
  33.         $customFieldSetRelationRepository $this->container->get('custom_field_set_relation.repository');
  34.         $data = [
  35.             'id' => '5a5ae26bc44f4366a41d637270680b83',
  36.             'customFieldSet' => $customFieldSetCategory,
  37.             'entityName' => 'category'            
  38.         ];
  39.         $customFieldSetRelationRepository->upsert([$data] , $context);
  40.         /** @var EntityRepositoryInterface $customFieldRepository */
  41.         $customFieldRepository $this->container->get('custom_field.repository'); 
  42.         $data = [                
  43.             [
  44.                 'id' => '363ebca67ccc4df0b94dba9e39956346',
  45.                 'name' => 'six_seo_text_listing_bottom_headline',
  46.                 'type' => 'html',
  47.                 'config' => [
  48.                     "label" => [
  49.                         "en-GB" => "SEO Text headline (under the listing)"
  50.                         "de-DE" => "SEO Text Überschrift (unterhalb des Listings)."
  51.                     ], 
  52.                     "helpText" => [
  53.                         "en-GB" => "SEO Text under the product listing"
  54.                         "de-DE" => "SEO Text unterhalb des Produktlisting. Für H Überschriften können Sie in diesen Feld direkt HTML-Tags, wie z.B. &lt;h2&gt;...&lt;/h2&gt; verwenden."
  55.                     ], 
  56.                     "componentName" => "sw-field"
  57.                     "customFieldType" => "text"
  58.                     "customFieldPosition" => 1
  59.                 ],
  60.                 'active' => boolval(1),
  61.                 'customFieldSet' => $customFieldSetCategory
  62.             ],
  63.             
  64.             [
  65.                 'id' => '09bbd80621494ea292ad27bc2b72edad',
  66.                 'name' => 'six_seo_text_listing_bottom_content',
  67.                 'type' => 'html',
  68.                 'config' => [
  69.                     "label" => [
  70.                         "en-GB" => "SEO Text content (under the listing)"
  71.                         "de-DE" => "SEO Text Inhalt (unterhalb des Listings )"
  72.                     ], 
  73.                     "helpText" => [
  74.                         "en-GB" => "SEO Text under the product listing"
  75.                         "de-DE" => "SEO Text unterhalb des Produktlisting"
  76.                     ], 
  77.                     "componentName" => "sw-text-editor"
  78.                     "customFieldType" => "textEditor"
  79.                     "customFieldPosition" => 2
  80.                 ],
  81.                 'active' => boolval(1),
  82.                 'customFieldSet' => $customFieldSetCategory
  83.             ],            
  84.             
  85.             [
  86.                 'id' => '619b28e9625b48baa37cd710470931c3',
  87.                 'name' => 'six_seo_text_sidebar_headline',
  88.                 'type' => 'html',
  89.                 'config' => [
  90.                     "label" => [
  91.                         "en-GB" => "SEO Sidebar headline"
  92.                         "de-DE" => "SEO Sidebar Überschrift"
  93.                     ], "helpText" => [
  94.                         "en-GB" => null
  95.                         "de-DE" => "Für H Überschriften können Sie in diesen Feld direkt HTML-Tags, wie z.B. &lt;h2&gt;...&lt;/h2&gt; verwenden."
  96.                     ], 
  97.                     "componentName" => "sw-field"
  98.                     "customFieldType" => "text"
  99.                     "customFieldPosition" => 3
  100.                 ],
  101.                 'active' => boolval(1),
  102.                 'customFieldSet' => $customFieldSetCategory
  103.             ],
  104.             
  105.             [
  106.                 'id' => '49906b4e905e49e9acfcba78542f2153',
  107.                 'name' => 'six_seo_text_sidebar_content',
  108.                 'type' => 'html',
  109.                 'config' => [
  110.                     "label" => [
  111.                         "en-GB" => "SEO Sidebar content"
  112.                         "de-DE" => "SEO Sidebar Inhalt"
  113.                     ], 
  114.                     "helpText" => [
  115.                         "en-GB" => null
  116.                         "de-DE" => null
  117.                     ], 
  118.                     "componentName" => "sw-text-editor"
  119.                     "customFieldType" => "textEditor"
  120.                     "customFieldPosition" => 4
  121.                 ],
  122.                 'active' => boolval(1),
  123.                 'customFieldSet' => $customFieldSetCategory
  124.             ],
  125.             
  126.             [
  127.                 'id' => '74781872bcff4eeba8c70a0b99930860',
  128.                 'name' => 'six_seo_text_footer_headline',
  129.                 'type' => 'html',
  130.                 'config' => [
  131.                     "label" => [
  132.                         "en-GB" => "SEO Footer headline"
  133.                         "de-DE" => "SEO Footer Überschrift"
  134.                     ], "helpText" => [
  135.                         "en-GB" => null
  136.                         "de-DE" => null
  137.                     ], 
  138.                     "componentName" => "sw-field"
  139.                     "customFieldType" => "text"
  140.                     "customFieldPosition" => 5
  141.                 ],
  142.                 'active' => boolval(1),
  143.                 'customFieldSet' => $customFieldSetCategory
  144.             ],
  145.             
  146.             [
  147.                 'id' => '8dbbf9d7b12441d28af35677ee150a84',
  148.                 'name' => 'six_seo_text_footer_content',
  149.                 'type' => 'html',
  150.                 'config' => [
  151.                     "label" => [
  152.                         "en-GB" => "SEO Footer content"
  153.                         "de-DE" => "SEO Footer Inhalt"
  154.                     ], 
  155.                     "helpText" => [
  156.                         "en-GB" => null
  157.                         "de-DE" => null
  158.                     ], 
  159.                     "componentName" => "sw-text-editor"
  160.                     "customFieldType" => "textEditor"
  161.                     "customFieldPosition" => 6
  162.                 ],
  163.                 'active' => boolval(1),
  164.                 'customFieldSet' => $customFieldSetCategory
  165.             ],                                
  166.         ];
  167.     
  168.         $customFieldRepository->upsert($data$context);
  169.     
  170.     }
  171.     public function removeCustomFields(Context $context): void {
  172.         //Removing custom_field_set
  173.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  174.         $customFieldSetRepository ->delete(
  175.             [
  176.                 ['id' => self::FIELDSET_ID_CATEGORY],
  177.             ],
  178.             $context
  179.         );
  180.     }
  181.     
  182.     public function install(InstallContext $context): void
  183.     {
  184.         $this->setupCustomFields($context->getContext());
  185.     }
  186.     public function update(UpdateContext $context): void
  187.     {
  188.         $this->setupCustomFields($context->getContext());
  189.     }
  190.     public function uninstall(UninstallContext $context): void
  191.     {
  192.         parent::uninstall($context);
  193.         if ($context->keepUserData()) {
  194.             return;
  195.         }
  196.         $this->removeCustomFields($context->getContext());
  197.     }
  198.     public function activate(ActivateContext $context): void
  199.     {
  200.         $this->setupCustomFields($context->getContext());
  201.         parent::activate($context);
  202.     }
  203.     public function deactivate(DeactivateContext $context): void
  204.     {
  205.         parent::deactivate($context);
  206.     }    
  207. }