<?php
namespace Six\CategorySeoText;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Plugin;
class SixCategorySeoText extends Plugin
{
public const FIELDSET_ID_CATEGORY = '9f4fed9b63e142d1acbd039a093794c1';
public function setupCustomFields(Context $context): void {
/** @var EntityRepositoryInterface $customFieldSetRepository */
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$customFieldSetCategory = [
'id' => self::FIELDSET_ID_CATEGORY,
'name' => 'six_seo_text_category',
'config' => [
'label' => [
'en-GB' => 'SEO Text (sixmedia)',
'de-DE' => 'SEO Text (sixmedia)',
],
'translated' => 'true'
],
'active' => boolval(1)
];
$customFieldSetRepository->upsert([$customFieldSetCategory], $context);
/** @var EntityRepositoryInterface $customFieldSetRelationRepository */
$customFieldSetRelationRepository = $this->container->get('custom_field_set_relation.repository');
$data = [
'id' => '5a5ae26bc44f4366a41d637270680b83',
'customFieldSet' => $customFieldSetCategory,
'entityName' => 'category'
];
$customFieldSetRelationRepository->upsert([$data] , $context);
/** @var EntityRepositoryInterface $customFieldRepository */
$customFieldRepository = $this->container->get('custom_field.repository');
$data = [
[
'id' => '363ebca67ccc4df0b94dba9e39956346',
'name' => 'six_seo_text_listing_bottom_headline',
'type' => 'html',
'config' => [
"label" => [
"en-GB" => "SEO Text headline (under the listing)",
"de-DE" => "SEO Text Überschrift (unterhalb des Listings)."
],
"helpText" => [
"en-GB" => "SEO Text under the product listing",
"de-DE" => "SEO Text unterhalb des Produktlisting. Für H Überschriften können Sie in diesen Feld direkt HTML-Tags, wie z.B. <h2>...</h2> verwenden."
],
"componentName" => "sw-field",
"customFieldType" => "text",
"customFieldPosition" => 1
],
'active' => boolval(1),
'customFieldSet' => $customFieldSetCategory
],
[
'id' => '09bbd80621494ea292ad27bc2b72edad',
'name' => 'six_seo_text_listing_bottom_content',
'type' => 'html',
'config' => [
"label" => [
"en-GB" => "SEO Text content (under the listing)",
"de-DE" => "SEO Text Inhalt (unterhalb des Listings )"
],
"helpText" => [
"en-GB" => "SEO Text under the product listing",
"de-DE" => "SEO Text unterhalb des Produktlisting"
],
"componentName" => "sw-text-editor",
"customFieldType" => "textEditor",
"customFieldPosition" => 2
],
'active' => boolval(1),
'customFieldSet' => $customFieldSetCategory
],
[
'id' => '619b28e9625b48baa37cd710470931c3',
'name' => 'six_seo_text_sidebar_headline',
'type' => 'html',
'config' => [
"label" => [
"en-GB" => "SEO Sidebar headline",
"de-DE" => "SEO Sidebar Überschrift"
], "helpText" => [
"en-GB" => null,
"de-DE" => "Für H Überschriften können Sie in diesen Feld direkt HTML-Tags, wie z.B. <h2>...</h2> verwenden."
],
"componentName" => "sw-field",
"customFieldType" => "text",
"customFieldPosition" => 3
],
'active' => boolval(1),
'customFieldSet' => $customFieldSetCategory
],
[
'id' => '49906b4e905e49e9acfcba78542f2153',
'name' => 'six_seo_text_sidebar_content',
'type' => 'html',
'config' => [
"label" => [
"en-GB" => "SEO Sidebar content",
"de-DE" => "SEO Sidebar Inhalt"
],
"helpText" => [
"en-GB" => null,
"de-DE" => null
],
"componentName" => "sw-text-editor",
"customFieldType" => "textEditor",
"customFieldPosition" => 4
],
'active' => boolval(1),
'customFieldSet' => $customFieldSetCategory
],
[
'id' => '74781872bcff4eeba8c70a0b99930860',
'name' => 'six_seo_text_footer_headline',
'type' => 'html',
'config' => [
"label" => [
"en-GB" => "SEO Footer headline",
"de-DE" => "SEO Footer Überschrift"
], "helpText" => [
"en-GB" => null,
"de-DE" => null
],
"componentName" => "sw-field",
"customFieldType" => "text",
"customFieldPosition" => 5
],
'active' => boolval(1),
'customFieldSet' => $customFieldSetCategory
],
[
'id' => '8dbbf9d7b12441d28af35677ee150a84',
'name' => 'six_seo_text_footer_content',
'type' => 'html',
'config' => [
"label" => [
"en-GB" => "SEO Footer content",
"de-DE" => "SEO Footer Inhalt"
],
"helpText" => [
"en-GB" => null,
"de-DE" => null
],
"componentName" => "sw-text-editor",
"customFieldType" => "textEditor",
"customFieldPosition" => 6
],
'active' => boolval(1),
'customFieldSet' => $customFieldSetCategory
],
];
$customFieldRepository->upsert($data, $context);
}
public function removeCustomFields(Context $context): void {
//Removing custom_field_set
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$customFieldSetRepository ->delete(
[
['id' => self::FIELDSET_ID_CATEGORY],
],
$context
);
}
public function install(InstallContext $context): void
{
$this->setupCustomFields($context->getContext());
}
public function update(UpdateContext $context): void
{
$this->setupCustomFields($context->getContext());
}
public function uninstall(UninstallContext $context): void
{
parent::uninstall($context);
if ($context->keepUserData()) {
return;
}
$this->removeCustomFields($context->getContext());
}
public function activate(ActivateContext $context): void
{
$this->setupCustomFields($context->getContext());
parent::activate($context);
}
public function deactivate(DeactivateContext $context): void
{
parent::deactivate($context);
}
}