Skip to content

Commit 9edd575

Browse files
committed
Support of the widget in itself
1 parent 471bc01 commit 9edd575

2 files changed

Lines changed: 103 additions & 75 deletions

File tree

system/modules/multicolumnwizard/MultiColumnWizard.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,12 @@ private function buildWidgetForDcGeneral(array $arrData, array &$arrField)
999999
$environment = $this->objDca->getEnvironment();
10001000
$properties = $environment->getDataDefinition()->getPropertiesDefinition();
10011001

1002-
$propertyClass = new \ReflectionClass($properties->getProperty($this->strId));
1002+
// Convert the property name for find the property in the definition.
1003+
$search = array('/([\[][0-9]{1,}[\]])/', '/[\[\]]/');
1004+
$replace = array('__', '');
1005+
$propertyName = trim(preg_replace($search, $replace, $this->id), '__');
1006+
1007+
$propertyClass = new \ReflectionClass($properties->getProperty($propertyName));
10031008
$property = $propertyClass->newInstance($arrField['name']);
10041009
$properties->addProperty($property);
10051010

system/modules/multicolumnwizard/src/MultiColumnWizard/DcGeneral/UpdateDataDefinition.php

Lines changed: 97 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace MultiColumnWizard\DcGeneral;
1313

1414
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\Properties\DefaultProperty;
15+
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\Properties\PropertyInterface;
16+
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\PropertiesDefinitionInterface;
1517
use ContaoCommunityAlliance\DcGeneral\Factory\Event\BuildDataDefinitionEvent;
1618

1719
/**
@@ -31,7 +33,7 @@ class UpdateDataDefinition
3133
*
3234
* @return void
3335
*/
34-
function addMcwFields(BuildDataDefinitionEvent $event)
36+
public function addMcwFields(BuildDataDefinitionEvent $event)
3537
{
3638
// Get the container and all properties.
3739
$container = $event->getContainer();
@@ -45,87 +47,108 @@ function addMcwFields(BuildDataDefinitionEvent $event)
4547
}
4648

4749
// Get the extra and make an own field from it.
48-
$config = $property->getExtra();
50+
$extra = $property->getExtra();
4951

5052
// If we have no data here, go to the next.
51-
if(empty($config['columnFields']) || !is_array($config['columnFields'])){
53+
if(empty($extra['columnFields']) || !is_array($extra['columnFields'])){
5254
continue;
5355
}
5456

55-
foreach ($config['columnFields'] as $fieldKey => $fieldConfig) {
56-
// Build the default name.
57-
$name = sprintf('%s__%s', $property->getName(), $fieldKey);
58-
59-
// Make a new field and fill it with the data from the config.
60-
$subProperty = new DefaultProperty($name);
61-
foreach ($fieldConfig as $key => $value) {
62-
switch ($key) {
63-
case 'label':
64-
$subProperty->setLabel($value);
65-
break;
66-
67-
case 'description':
68-
if (!$subProperty->getDescription()) {
69-
$subProperty->setDescription($value);
70-
}
71-
break;
72-
73-
case 'default':
74-
if (!$subProperty->getDefaultValue()) {
75-
$subProperty->setDefaultValue($value);
76-
}
77-
break;
78-
79-
case 'exclude':
80-
$subProperty->setExcluded((bool)$value);
81-
break;
82-
83-
case 'search':
84-
$subProperty->setSearchable((bool)$value);
85-
break;
86-
87-
case 'filter':
88-
$subProperty->setFilterable((bool)$value);
89-
break;
90-
91-
case 'inputType':
92-
$subProperty->setWidgetType($value);
93-
break;
94-
95-
case 'options':
96-
$subProperty->setOptions($value);
97-
break;
98-
99-
case 'explanation':
100-
$subProperty->setExplanation($value);
101-
break;
102-
103-
case 'eval':
104-
$subProperty->setExtra(
105-
array_merge(
106-
(array) $subProperty->getExtra(),
107-
(array) $value
108-
)
109-
);
110-
break;
111-
112-
case 'reference':
113-
$subProperty->setExtra(
114-
array_merge(
115-
(array) $subProperty->getExtra(),
116-
array('reference' => &$value['reference'])
117-
)
118-
);
119-
break;
120-
121-
default:
122-
}
123-
}
57+
$this->addPropertyToDefinition($extra, $property, $properties);
58+
}
59+
}
12460

125-
// Add all to the current list.
126-
$properties->addProperty($subProperty);
61+
private function addPropertyToDefinition(
62+
array $extra,
63+
PropertyInterface $property,
64+
PropertiesDefinitionInterface $properties
65+
) {
66+
foreach ($extra['columnFields'] as $fieldKey => $fieldConfig) {
67+
// Build the default name.
68+
$name = sprintf('%s__%s', $property->getName(), $fieldKey);
69+
70+
// Make a new field and fill it with the data from the config.
71+
$subProperty = new DefaultProperty($name);
72+
foreach ($fieldConfig as $key => $value) {
73+
switch ($key) {
74+
case 'label':
75+
$subProperty->setLabel($value);
76+
break;
77+
78+
case 'description':
79+
if (!$subProperty->getDescription()) {
80+
$subProperty->setDescription($value);
81+
}
82+
break;
83+
84+
case 'default':
85+
if (!$subProperty->getDefaultValue()) {
86+
$subProperty->setDefaultValue($value);
87+
}
88+
break;
89+
90+
case 'exclude':
91+
$subProperty->setExcluded((bool) $value);
92+
break;
93+
94+
case 'search':
95+
$subProperty->setSearchable((bool) $value);
96+
break;
97+
98+
case 'filter':
99+
$subProperty->setFilterable((bool) $value);
100+
break;
101+
102+
case 'inputType':
103+
$subProperty->setWidgetType($value);
104+
break;
105+
106+
case 'options':
107+
$subProperty->setOptions($value);
108+
break;
109+
110+
case 'explanation':
111+
$subProperty->setExplanation($value);
112+
break;
113+
114+
case 'eval':
115+
$subProperty->setExtra(
116+
array_merge(
117+
(array) $subProperty->getExtra(),
118+
(array) $value
119+
)
120+
);
121+
break;
122+
123+
case 'reference':
124+
$subProperty->setExtra(
125+
array_merge(
126+
(array) $subProperty->getExtra(),
127+
array('reference' => &$value['reference'])
128+
)
129+
);
130+
break;
131+
132+
default:
133+
}
127134
}
135+
136+
// Add all to the current list.
137+
$properties->addProperty($subProperty);
138+
$this->addSubMultiColumnWizardProperty($subProperty, $properties);
139+
}
140+
}
141+
142+
private function addSubMultiColumnWizardProperty(
143+
PropertyInterface $property,
144+
PropertiesDefinitionInterface $properties
145+
) {
146+
$extra = $property->getExtra();
147+
148+
if (empty($extra['columnFields']) || !is_array($extra['columnFields'])) {
149+
return;
128150
}
129151

152+
$this->addPropertyToDefinition($extra, $property, $properties);
130153
}
131154
}

0 commit comments

Comments
 (0)