Skip to content

Commit 4aaad0f

Browse files
committed
[Studio] form bundle updates
1 parent c3e2f60 commit 4aaad0f

File tree

7 files changed

+187
-138
lines changed

7 files changed

+187
-138
lines changed

src/CoreShop/Bundle/StudioFormBundle/Form/Type/Demo/EntityChoiceDemoType.php renamed to src/CoreShop/Bundle/CoreBundle/Form/Type/Demo/EntityChoiceDemoType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
namespace CoreShop\Bundle\StudioFormBundle\Form\Type\Demo;
18+
namespace CoreShop\Bundle\CoreBundle\Form\Type\Demo;
1919

2020
use CoreShop\Bundle\AddressBundle\Form\Type\CountryChoiceType;
2121
use CoreShop\Bundle\AddressBundle\Form\Type\StateChoiceType;

src/CoreShop/Bundle/CoreBundle/Resources/assets/pimcore-studio/src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ import {
3434
AssignToExistingCompanyPanel,
3535
customerCompanyAssignmentWidgetRestorer,
3636
} from './modules/customer-company-assignment'
37+
import { registerCoreStudioFormDemoTabs } from './modules/studio-form-demos/registerDemoTabs'
3738

3839
const plugin: IAbstractPlugin = {
3940
name: 'coreshop-core',
4041

4142
onInit() {
43+
registerCoreStudioFormDemoTabs()
44+
4245
// Register DynamicTypes
4346
const objectDataRegistry = container.get<DynamicTypeObjectDataRegistry>(
4447
serviceIds['DynamicTypes/ObjectDataRegistry']
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
}

src/CoreShop/Bundle/CoreBundle/Resources/config/services/form.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,8 @@ services:
127127
CoreShop\Bundle\CoreBundle\Form\Extension\StudioOrderShipmentCreationTypeExtension:
128128
tags:
129129
- { name: form.type_extension, extended_type: CoreShop\Bundle\OrderBundle\Form\Type\Studio\OrderShipmentCreationType }
130+
131+
CoreShop\Bundle\CoreBundle\Form\Type\Demo\EntityChoiceDemoType:
132+
tags:
133+
- { name: form.type }
134+
- { name: coreshop.studio_form }

src/CoreShop/Bundle/StudioFormBundle/Form/Schema/RuleFormSchemaCollector.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
namespace CoreShop\Bundle\StudioFormBundle\Form\Schema;
1919

20-
use CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistryInterface;
2120
use Psr\Log\LoggerInterface;
2221

2322
final class RuleFormSchemaCollector
@@ -39,7 +38,7 @@ public function __construct(
3938
*
4039
* @return array<string, FormSchema> Map of block prefix to FormSchema
4140
*/
42-
public function collectSchemas(FormTypeRegistryInterface $formTypeRegistry, array $typeNames): array
41+
public function collectSchemas(object $formTypeRegistry, array $typeNames): array
4342
{
4443
return $this->collectSchemasWithTypeMap($formTypeRegistry, $typeNames)['schemas'];
4544
}
@@ -54,17 +53,23 @@ public function collectSchemas(FormTypeRegistryInterface $formTypeRegistry, arra
5453
* schemaByType: array<string, string>
5554
* }
5655
*/
57-
public function collectSchemasWithTypeMap(FormTypeRegistryInterface $formTypeRegistry, array $typeNames): array
56+
public function collectSchemasWithTypeMap(object $formTypeRegistry, array $typeNames): array
5857
{
58+
$hasTypeCallable = \Closure::fromCallable([$formTypeRegistry, 'has']);
59+
$getTypeCallable = \Closure::fromCallable([$formTypeRegistry, 'get']);
60+
5961
$schemas = [];
6062
$schemaByType = [];
6163

6264
foreach ($typeNames as $typeName) {
63-
if (!$formTypeRegistry->has($typeName, 'default')) {
65+
if (!(bool) $hasTypeCallable($typeName, 'default')) {
6466
continue;
6567
}
6668

67-
$formTypeClass = $formTypeRegistry->get($typeName, 'default');
69+
$formTypeClass = $getTypeCallable($typeName, 'default');
70+
if (!is_string($formTypeClass)) {
71+
continue;
72+
}
6873

6974
try {
7075
$schema = $this->generator->generate($formTypeClass);

0 commit comments

Comments
 (0)