<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
it-bens / shopware-code-based-plugin-configuration example snippets
public function executeComposerCommands(): bool
{
return true;
}
use ITB\ShopwareCodeBasedPluginConfiguration\DependencyInjection\CompilerPassHelper;
public function build(ContainerBuilder $container): void
{
// ...
parent::build($container);
CompilerPassHelper::addCompilerPassesToContainerBuilder($container);
}
use ITB\ShopwareCodeBasedPluginConfiguration\DependencyInjection\CompilerPass\ConfigurationCardConfigReaderPass;
use ITB\ShopwareCodeBasedPluginConfiguration\DependencyInjection\CompilerPass\ConfigurationCardProviderTaggingPass;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
public function build(ContainerBuilder $container): void
{
// ...
parent::build($container);
$container->addCompilerPass(new ConfigurationCardProviderTaggingPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1000);
$container->addCompilerPass(new ConfigurationCardConfigReaderPass());
}
use ITB\ShopwareCodeBasedPluginConfiguration\DependencyInjection\CompilerPass\ConfigurationCardConfigReaderPass;
use ITB\ShopwareCodeBasedPluginConfiguration\DependencyInjection\CompilerPass\ConfigurationCardConfigSaverPass;
use ITB\ShopwareCodeBasedPluginConfiguration\DependencyInjection\CompilerPass\ConfigurationCardProviderTaggingPass;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
public function build(ContainerBuilder $container): void
{
// ...
parent::build($container);
$container->addCompilerPass(new ConfigurationCardProviderTaggingPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1000);
$container->addCompilerPass(new ConfigurationCardConfigReaderPass());
$container->addCompilerPass(new ConfigurationCardConfigSaverPass());
}
use ITB\ShopwareCodeBasedPluginConfiguration\ConfigurationCard;
use ITB\ShopwareCodeBasedPluginConfiguration\ConfigurationInputField\BoolField;
use ITB\ShopwareCodeBasedPluginConfiguration\ConfigurationInputField\IntegerField;
use ITB\ShopwareCodeBasedPluginConfiguration\ConfigurationInputField\SingleSelectField;
use ITB\ShopwareCodeBasedPluginConfiguration\ConfigurationInputField\SingleSelectFieldOption;
use ITB\ShopwareCodeBasedPluginConfiguration\ConfigurationInputField\TextField;
use ITB\ShopwareCodeBasedPluginConfiguration\GeneralFieldInputInformation;
$enabledFieldInformation = new GeneralFieldInputInformation(
name: 'enabled',
labelInEnglish: 'Enabled',
labelInGerman: 'Aktiviert',
helpTextInEnglish: 'Enable or disable the feature',
helpTextInGerman: 'Aktiviere oder deaktiviere das Feature'
);
$enabledField = new BoolField(new GeneralFieldInformation(generalInformation: $enabledFieldInformation, defaultValue: false);
$integerFieldInformation = new GeneralFieldInputInformation(
name: 'position',
labelInEnglish: 'Position',
labelInGerman: 'Position',
helpTextInEnglish: 'The position in the list',
helpTextInGerman: 'Die Position in der Liste'
);
$integerField = new IntegerField(new GeneralFieldInformation(generalInformation: $integerFieldInformation, defaultValue: 0);
$selectFieldInformation = new GeneralFieldInputInformation(
name: 'color',
labelInEnglish: 'Color',
labelInGerman: 'Farbe',
helpTextInEnglish: 'The color of the item',
helpTextInGerman: 'Die Farbe des Elements'
);
$selectField = new SingleSelectField(
new GeneralFieldInformation(generalInformation: $selectFieldInformation, defaultValue: 'red'),
[
new SingleSelectFieldOption(id: 'red', nameInEnglish: 'Red', nameInGerman: 'Rot'),
new SingleSelectFieldOption(id: 'blue', nameInEnglish: 'Blue', nameInGerman: 'Blau'),
new SingleSelectFieldOption(id: 'green', nameInEnglish: 'Green', nameInGerman: 'Grün'),
]
);
$textFieldInformation = new GeneralFieldInputInformation(
name: 'description',
labelInEnglish: 'Description',
labelInGerman: 'Beschreibung',
helpTextInEnglish: 'A description of the item',
helpTextInGerman: 'Eine Beschreibung des Elements'
);
$textField = new TextField(new GeneralFieldInformation(generalInformation: $textFieldInformation, defaultValue: '');
$configurationCard = new ConfigurationCard(
titleInEnglish: 'General Settings',
titleInGerman: 'Allgemeine Einstellungen',
inputFields: [$enabledField, $integerField, $selectField, $textField]
);
/**
* @return class-string<Bundle>[]
*/
public function getBundleClasses(): array {
return [
YourPluginClass::class
];
}
use ITB\ShopwareCodeBasedPluginConfiguration\Attribute\AsConfigurationCardProvider;
#[AsConfigurationCardProvider(priority: 1000)]
...
/**
* @return ConfigurationCard[]
*/
public function getConfigurationCards(): array {
return $this->configurationCards;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.