Skip to content

Commit 3771eb8

Browse files
authored
Merge pull request #247 from baumannsven/hotfix/3.3.16
Hotfix/3.3.16
2 parents 48bf286 + 9edd575 commit 3771eb8

3 files changed

Lines changed: 109 additions & 193 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/config/event_listeners.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,21 @@
44
* Contao Open Source CMS
55
*
66
* @copyright MEN AT WORK 2017
7-
* @author Sven Baumann <baumann.sv@gmail.com> 2017
87
* @package MultiColumnWizard
98
* @license LGPL
109
* @filesource
1110
*/
1211

13-
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\BuildWidgetEvent;
14-
use ContaoCommunityAlliance\DcGeneral\DcGeneralEvents;
15-
use ContaoCommunityAlliance\DcGeneral\Factory\Event\PopulateEnvironmentEvent;
12+
use ContaoCommunityAlliance\DcGeneral\Factory\Event\BuildDataDefinitionEvent;
1613
use MultiColumnWizard\DcGeneral\UpdateDataDefinition;
1714

18-
if (class_exists(DcGeneralEvents::class)) {
15+
if (class_exists(BuildDataDefinitionEvent::class)) {
1916
return array
2017
(
21-
PopulateEnvironmentEvent::NAME => array(
18+
BuildDataDefinitionEvent::NAME => array(
2219
array(
2320
array(new UpdateDataDefinition(), 'addMcwFields'),
24-
UpdateDataDefinition::POPULATE_PRIORITY
25-
)
26-
),
27-
BuildWidgetEvent::NAME => array(
28-
array(
29-
array(new UpdateDataDefinition(), 'setModalValue'),
30-
UpdateDataDefinition::BUILD_WIDGET_PRIORITY
21+
UpdateDataDefinition::PRIORITY
3122
)
3223
)
3324
);

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

Lines changed: 99 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -11,83 +11,33 @@
1111

1212
namespace MultiColumnWizard\DcGeneral;
1313

14-
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\BuildWidgetEvent;
1514
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\Properties\DefaultProperty;
16-
use ContaoCommunityAlliance\DcGeneral\EnvironmentInterface;
17-
use ContaoCommunityAlliance\DcGeneral\Factory\Event\PopulateEnvironmentEvent;
15+
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\Properties\PropertyInterface;
16+
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\PropertiesDefinitionInterface;
17+
use ContaoCommunityAlliance\DcGeneral\Factory\Event\BuildDataDefinitionEvent;
1818

1919
/**
2020
* Class UpdateDataDefinition
2121
*
22-
* @author Sven Baumann <baumann.sv@gmail.com> 2017
23-
* @package MultiColumnWizard\DcGeneral
22+
* @package MultiColumnWizard\DcGeneral
2423
*/
2524
class UpdateDataDefinition
2625
{
27-
const POPULATE_PRIORITY = -500000;
28-
const BUILD_WIDGET_PRIORITY = 500000;
26+
const PRIORITY = -500000;
2927

3028
/**
3129
* Add all fields from the MCW to the DCA. This is needed for some fields, because other components need this
3230
* to create the widget/view etc.
3331
*
34-
* @param PopulateEnvironmentEvent $event
32+
* @param BuildDataDefinitionEvent $event
3533
*
3634
* @return void
3735
*/
38-
public function addMcwFields(PopulateEnvironmentEvent $event)
36+
public function addMcwFields(BuildDataDefinitionEvent $event)
3937
{
40-
$inputPropertyName = $this->getInputPropertyName($event->getEnvironment());
41-
42-
// If the property don´t find in post or get then do nothing. The property must only add for popups.
43-
if (false === (bool) $inputPropertyName) {
44-
return;
45-
}
46-
47-
// Add the sub properties of MCW in modal view or in ajax call.
48-
$this->buildProperty($inputPropertyName, $event->getEnvironment());
49-
}
50-
51-
/**
52-
* Set the used modal value.
53-
* By Widget::getPost the post key split in parts, then don`t find the return value from modal.
54-
*
55-
* @param BuildWidgetEvent $event The event.
56-
*
57-
* @return void
58-
*/
59-
public function setModalValue(BuildWidgetEvent $event)
60-
{
61-
$environment = $event->getEnvironment();
62-
$sessionStorage = $environment->getSessionStorage();
63-
$session = (array) $sessionStorage->get('MCW_MODAL_UPDATE');
64-
65-
if (false === isset($session[md5($event->getProperty()->getName())])) {
66-
return;
67-
}
68-
69-
$input = $environment->getInputProvider();
70-
$data = $session[md5($event->getProperty()->getName())];
71-
72-
$input->setValue($data['key'], $input->getValue($data['valueFrom']));
73-
74-
unset($session[md5($event->getProperty()->getName())]);
75-
$sessionStorage->set('MCW_MODAL_UPDATE', $session);
76-
}
77-
78-
/**
79-
* Build the MCW column property and add to properties.
80-
*
81-
* @param string $propertyName The property name.
82-
*
83-
* @param EnvironmentInterface $environment The environment.
84-
*
85-
* @return void
86-
*/
87-
private function buildProperty($propertyName, EnvironmentInterface $environment)
88-
{
89-
$dataDefinition = $environment->getDataDefinition();
90-
$properties = $dataDefinition->getPropertiesDefinition();
38+
// Get the container and all properties.
39+
$container = $event->getContainer();
40+
$properties = $container->getPropertiesDefinition();
9141

9242
/** @var DefaultProperty $property */
9343
foreach ($properties as $property) {
@@ -97,138 +47,108 @@ private function buildProperty($propertyName, EnvironmentInterface $environment)
9747
}
9848

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

10252
// If we have no data here, go to the next.
103-
if (empty($config['columnFields']) || !is_array($config['columnFields'])) {
53+
if(empty($extra['columnFields']) || !is_array($extra['columnFields'])){
10454
continue;
10555
}
10656

107-
foreach ($config['columnFields'] as $fieldKey => $fieldConfig) {
108-
if ((true === $properties->hasProperty($propertyName))
109-
|| (false === strpos($propertyName, $property->getName()))
110-
|| ('[' . $fieldKey . ']' !== substr($propertyName, -strlen('[' . $fieldKey . ']')))
111-
) {
112-
continue;
113-
}
57+
$this->addPropertyToDefinition($extra, $property, $properties);
58+
}
59+
}
11460

115-
// Make a new field and fill it with the data from the config.
116-
$subProperty = new DefaultProperty($propertyName);
117-
foreach ($fieldConfig as $key => $value) {
118-
switch ($key) {
119-
case 'label':
120-
$subProperty->setLabel($value);
121-
break;
122-
123-
case 'description':
124-
if (!$subProperty->getDescription()) {
125-
$subProperty->setDescription($value);
126-
}
127-
break;
128-
129-
case 'default':
130-
if (!$subProperty->getDefaultValue()) {
131-
$subProperty->setDefaultValue($value);
132-
}
133-
break;
134-
135-
case 'exclude':
136-
$subProperty->setExcluded((bool) $value);
137-
break;
138-
139-
case 'search':
140-
$subProperty->setSearchable((bool) $value);
141-
break;
142-
143-
case 'filter':
144-
$subProperty->setFilterable((bool) $value);
145-
break;
146-
147-
case 'inputType':
148-
$subProperty->setWidgetType($value);
149-
break;
150-
151-
case 'options':
152-
$subProperty->setOptions($value);
153-
break;
154-
155-
case 'explanation':
156-
$subProperty->setExplanation($value);
157-
break;
158-
159-
case 'eval':
160-
$subProperty->setExtra(
161-
array_merge(
162-
(array) $subProperty->getExtra(),
163-
(array) $value
164-
)
165-
);
166-
break;
167-
168-
case 'reference':
169-
$subProperty->setExtra(
170-
array_merge(
171-
(array) $subProperty->getExtra(),
172-
array('reference' => &$value['reference'])
173-
)
174-
);
175-
break;
176-
177-
default:
178-
}
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:
179133
}
180-
181-
$properties->addProperty($subProperty);
182-
183-
$subExtra = $subProperty->getExtra();
184-
185-
// Fore some widgets must declare the evaluation in the data container configuration.
186-
$GLOBALS['TL_DCA'][$dataDefinition->getName()]['fields'][$subProperty->getName()]['eval'] = $subExtra;
187134
}
135+
136+
// Add all to the current list.
137+
$properties->addProperty($subProperty);
138+
$this->addSubMultiColumnWizardProperty($subProperty, $properties);
188139
}
189140
}
190141

191-
/**
192-
* Get the input property from input.
193-
*
194-
* @param EnvironmentInterface $environment The environment.
195-
*
196-
* @return string
197-
*/
198-
private function getInputPropertyName(EnvironmentInterface $environment)
199-
{
200-
$input = $environment->getInputProvider();
142+
private function addSubMultiColumnWizardProperty(
143+
PropertyInterface $property,
144+
PropertiesDefinitionInterface $properties
145+
) {
146+
$extra = $property->getExtra();
201147

202-
if ((true === $input->hasParameter('field'))
203-
&& (false === count($input->getParameter('field')))
204-
) {
205-
return $input->getParameter('field');
206-
}
207-
if ((true === $input->hasValue('name'))
208-
&& (false === count($input->getValue('name')))
209-
) {
210-
$sessionStorage = $environment->getSessionStorage();
211-
$session = $sessionStorage->get('MCW_MODAL_UPDATE');
212-
213-
$chunks = explode(
214-
'::::',
215-
str_replace(
216-
array('][', '[', ']'),
217-
array('::::', '::::', ''),
218-
$input->getValue('name')
219-
)
220-
);
221-
222-
$session[md5($input->getValue('name'))] = array(
223-
'key' => array_shift($chunks),
224-
'valueFrom' => $input->getValue('name')
225-
);
226-
227-
$sessionStorage->set('MCW_MODAL_UPDATE', $session);
228-
229-
return $input->getValue('name');
148+
if (empty($extra['columnFields']) || !is_array($extra['columnFields'])) {
149+
return;
230150
}
231151

232-
return '';
152+
$this->addPropertyToDefinition($extra, $property, $properties);
233153
}
234154
}

0 commit comments

Comments
 (0)