<?php declare(strict_types=1);
namespace digi1\digi1Moretabsforproductdetailpage;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Core\System\CustomField\CustomFieldTypes;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
class digi1Moretabsforproductdetailpage extends Plugin {
public function install(InstallContext $installContext): void {
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('name', 'digi1_owntabs'));
$result = $customFieldSetRepository->searchIds($criteria, $installContext->getContext());
if ($result->getTotal() == 0) {
$customFieldSetRepository->create([[
'name' => 'digi1_owntabs',
'config' => [
'label' => [
'de-DE' => 'Tabs',
'en-GB' => 'tabs'
],
'translated' => true
],
'customFields' => [
[
'name' => 'digi1_owntabs_tab1headline',
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => [
'de-DE' => 'Tab 1 Überschrift',
'en-GB' => 'tab 1 headline'
],
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 1,
'type' => 'text'
]
],
[
'name' => 'digi1_owntabs_tab1content',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => [
'de-DE' => 'Tab 1 Inhalt',
'en-GB' => 'tab 1 content'
],
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'customFieldPosition' => 2
]
],
[
'name' => 'digi1_owntabs_tab2headline',
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => [
'de-DE' => 'Tab 2 Überschrift',
'en-GB' => 'tab 2 headline'
],
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 3,
'type' => 'text'
]
],
[
'name' => 'digi1_owntabs_tab2content',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => [
'de-DE' => 'Tab 2 Inhalt',
'en-GB' => 'tab 2 content'
],
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'customFieldPosition' => 4
]
],
[
'name' => 'digi1_owntabs_tab3headline',
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => [
'de-DE' => 'Tab 3 Überschrift',
'en-GB' => 'tab 3 headline'
],
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 5,
'type' => 'text'
]
],
[
'name' => 'digi1_owntabs_tab3content',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => [
'de-DE' => 'Tab 3 Inhalt',
'en-GB' => 'tab 3 content'
],
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'customFieldPosition' => 6
]
],
[
'name' => 'digi1_owntabs_tab4headline',
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => [
'de-DE' => 'Tab 4 Überschrift',
'en-GB' => 'tab 4 headline'
],
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 7,
'type' => 'text'
]
],
[
'name' => 'digi1_owntabs_tab4content',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => [
'de-DE' => 'Tab 4 Inhalt',
'en-GB' => 'tab 4 content'
],
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'customFieldPosition' => 8
]
],
[
'name' => 'digi1_owntabs_tab5headline',
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => [
'de-DE' => 'Tab 5 Überschrift',
'en-GB' => 'tab 5 headline'
],
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 9,
'type' => 'text'
]
],
[
'name' => 'digi1_owntabs_tab5content',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => [
'de-DE' => 'Tab 5 Inhalt',
'en-GB' => 'tab 5 content'
],
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'customFieldPosition' => 9
]
]
],
'relations' => [
['entityName' => 'product']
]
]], $installContext->getContext());
}
parent::install($installContext);
}
public function postInstall(InstallContext $installContext): void {
parent::postInstall($installContext);
}
public function update(UpdateContext $updateContext): void {
}
public function postUpdate(UpdateContext $updateContext): void {
}
public function activate(ActivateContext $activateContext): void {
parent::activate($activateContext);
}
public function deactivate(DeactivateContext $deactivateContext): void {
parent::deactivate($deactivateContext);
}
public function uninstall(UninstallContext $uninstallContext): void {
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('name', 'digi1_owntabs'));
$result = $customFieldSetRepository->searchIds($criteria, $uninstallContext->getContext());
if ($result->getTotal() > 0 && !$uninstallContext->keepUserData()) {
$data = $result->getDataOfId($result->firstId());
$customFieldSetRepository->delete([$data], $uninstallContext->getContext());
}
parent::uninstall($uninstallContext);
}
}