|
| 1 | +/** |
| 2 | + * CoreShop CoreBundle StudioForm Demo Tab Extensions |
| 3 | + * |
| 4 | + * Registers Core-specific demo tabs in the StudioForm demo widget. |
| 5 | + * |
| 6 | + * This source file is available under the terms of the |
| 7 | + * CoreShop Commercial License (CCL) |
| 8 | + * Full copyright and license information is available in |
| 9 | + * LICENSE.md which is distributed with this source code. |
| 10 | + * |
| 11 | + * @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.com) |
| 12 | + * @license CoreShop Commercial License (CCL) |
| 13 | + */ |
| 14 | + |
| 15 | +interface DemoTabDefinition { |
| 16 | + key: string |
| 17 | + label: string |
| 18 | + blockPrefix: string |
| 19 | + description: string |
| 20 | + phpSource: string |
| 21 | +} |
| 22 | + |
| 23 | +interface WindowWithCoreShopDemoTabs extends Window { |
| 24 | + coreshopStudioFormDemoTabs?: DemoTabDefinition[] |
| 25 | +} |
| 26 | + |
| 27 | +const ENTITY_CHOICES_PHP = `final class EntityChoiceDemoType extends AbstractType |
| 28 | +{ |
| 29 | + public function buildForm(FormBuilderInterface $builder, array $options): void |
| 30 | + { |
| 31 | + $builder |
| 32 | + ->add('country', CountryChoiceType::class, [ |
| 33 | + 'label' => 'Country (Single)', |
| 34 | + 'required' => false, |
| 35 | + ]) |
| 36 | + ->add('countries', CountryChoiceType::class, [ |
| 37 | + 'label' => 'Countries (Multiple)', |
| 38 | + 'multiple' => true, |
| 39 | + 'required' => false, |
| 40 | + ]) |
| 41 | + ->add('state', StateChoiceType::class, [ |
| 42 | + 'label' => 'State (Single)', |
| 43 | + 'required' => false, |
| 44 | + ]) |
| 45 | + ->add('states', StateChoiceType::class, [ |
| 46 | + 'label' => 'States (Multiple)', |
| 47 | + 'multiple' => true, |
| 48 | + 'required' => false, |
| 49 | + ]) |
| 50 | + ->add('zone', ZoneChoiceType::class, [ |
| 51 | + 'label' => 'Zone', |
| 52 | + 'required' => false, |
| 53 | + ]) |
| 54 | + ->add('zones', ZoneChoiceType::class, [ |
| 55 | + 'label' => 'Zones (Multiple)', |
| 56 | + 'multiple' => true, |
| 57 | + 'required' => false, |
| 58 | + ]) |
| 59 | + ->add('currency', CurrencyChoiceType::class, [ |
| 60 | + 'label' => 'Currency (Single)', |
| 61 | + 'required' => false, |
| 62 | + ]) |
| 63 | + ->add('currencies', CurrencyChoiceType::class, [ |
| 64 | + 'label' => 'Currencies (Multiple)', |
| 65 | + 'multiple' => true, |
| 66 | + 'required' => false, |
| 67 | + ]) |
| 68 | + ->add('store', StoreChoiceType::class, [ |
| 69 | + 'label' => 'Store', |
| 70 | + 'required' => false, |
| 71 | + ]) |
| 72 | + ->add('stores', StoreChoiceType::class, [ |
| 73 | + 'label' => 'Stores (Multiple)', |
| 74 | + 'multiple' => true, |
| 75 | + 'required' => false, |
| 76 | + ]) |
| 77 | + ->add('paymentProvider', PaymentProviderChoiceType::class, [ |
| 78 | + 'label' => 'Payment Provider (Single)', |
| 79 | + 'required' => false, |
| 80 | + ]) |
| 81 | + ->add('paymentProviders', PaymentProviderChoiceType::class, [ |
| 82 | + 'label' => 'Payment Providers (Multiple)', |
| 83 | + 'multiple' => true, |
| 84 | + 'required' => false, |
| 85 | + ]) |
| 86 | + ->add('taxRate', TaxRateChoiceType::class, [ |
| 87 | + 'label' => 'Tax Rate (Single)', |
| 88 | + 'required' => false, |
| 89 | + ]) |
| 90 | + ->add('taxRates', TaxRateChoiceType::class, [ |
| 91 | + 'label' => 'Tax Rates (Multiple)', |
| 92 | + 'multiple' => true, |
| 93 | + 'required' => false, |
| 94 | + ]) |
| 95 | + ->add('taxRuleGroup', TaxRuleGroupChoiceType::class, [ |
| 96 | + 'label' => 'Tax Rule Group (Single)', |
| 97 | + 'required' => false, |
| 98 | + ]) |
| 99 | + ->add('taxRuleGroups', TaxRuleGroupChoiceType::class, [ |
| 100 | + 'label' => 'Tax Rule Groups (Multiple)', |
| 101 | + 'multiple' => true, |
| 102 | + 'required' => false, |
| 103 | + ]) |
| 104 | + ; |
| 105 | + } |
| 106 | +
|
| 107 | + public function getBlockPrefix(): string |
| 108 | + { |
| 109 | + return 'coreshop_demo_entity_choices'; |
| 110 | + } |
| 111 | +}` |
| 112 | + |
| 113 | +const entityChoicesDemoTab: DemoTabDefinition = { |
| 114 | + key: 'entity-choices', |
| 115 | + label: 'Entity Choices', |
| 116 | + blockPrefix: 'coreshop_demo_entity_choices', |
| 117 | + description: 'CoreShop entity ChoiceTypes rendered via EntityChoiceWidget: Country, State, Zone, Currency, Store, Payment Provider, Tax Rate, Tax Rule Group - with single and multi-select variants.', |
| 118 | + phpSource: ENTITY_CHOICES_PHP, |
| 119 | +} |
| 120 | + |
| 121 | +export const registerCoreStudioFormDemoTabs = (): void => { |
| 122 | + const windowWithCoreShopDemoTabs = window as WindowWithCoreShopDemoTabs |
| 123 | + const existingTabs = windowWithCoreShopDemoTabs.coreshopStudioFormDemoTabs ?? [] |
| 124 | + |
| 125 | + const entityChoicesTabExists = existingTabs.some((tab) => { |
| 126 | + return tab.key === entityChoicesDemoTab.key || tab.blockPrefix === entityChoicesDemoTab.blockPrefix |
| 127 | + }) |
| 128 | + |
| 129 | + if (!entityChoicesTabExists) { |
| 130 | + windowWithCoreShopDemoTabs.coreshopStudioFormDemoTabs = [...existingTabs, entityChoicesDemoTab] |
| 131 | + } |
| 132 | +} |
0 commit comments