Skip to content

Commit 703d849

Browse files
committed
Add MCW in MCW support
Add a new function to find a MCW config in a MCW.
1 parent 20319c9 commit 703d849

File tree

1 file changed

+63
-22
lines changed

1 file changed

+63
-22
lines changed

src/EventListener/Mcw/CreateWidget.php

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,15 @@ public function createWidgetContao(CreateWidgetEvent $event)
7676
if (Input::get('act') == 'editAll') {
7777
$fieldName = \preg_replace('/(.*)_[0-9a-zA-Z]+$/', '$1', $fieldName);
7878
}
79-
$dcDriver->field = $fieldName;
79+
80+
// A MCW in a MCW has a path.
81+
$path = \preg_split('/[\[|\]]/i', $fieldName);
82+
$path = array_filter($path, 'strlen');
83+
84+
// The first should be the default MCW on the root level.
85+
if (count($path) > 1) {
86+
$fieldName = $path[0];
87+
}
8088

8189
// The field does not exist
8290
if (!isset($GLOBALS['TL_DCA'][$dcDriver->table]['fields'][$fieldName])) {
@@ -93,29 +101,62 @@ public function createWidgetContao(CreateWidgetEvent $event)
93101
throw new BadRequestHttpException('Bad request');
94102
}
95103

96-
$inputType = $GLOBALS['TL_DCA'][$dcDriver->table]['fields'][$fieldName]['inputType'];
97-
98-
/** @var string $widgetClassName */
99-
$widgetClassName = $GLOBALS['BE_FFL'][$inputType];
100-
101-
/** @var MultiColumnWizard $widget */
102-
/** @var MultiColumnWizard $widgetClassName */
103-
$widget = new $widgetClassName(
104-
$widgetClassName::getAttributesFromDca(
105-
$GLOBALS['TL_DCA'][$dcDriver->table]['fields'][$fieldName],
106-
$dcDriver->inputName,
107-
'',
108-
$fieldName,
109-
$dcDriver->table,
110-
$dcDriver
111-
)
104+
// MCW in MCW will generate a path, all else will be a array with one element.
105+
$this->loadDcaSettingInDepth(
106+
$dcDriver,
107+
$GLOBALS['TL_DCA'][$dcDriver->table]['fields'],
108+
$path,
109+
$event
112110
);
111+
}
113112

114-
// Set some more information.
115-
$widget->currentRecord = $dcDriver->id;
116-
$widget->activeRecord = $dcDriver->activeRecord;
113+
/**
114+
* @return void
115+
*/
116+
private function loadDcaSettingInDepth($dcDriver, $dca, $path, $event)
117+
{
118+
$currentElement = $path[0];
119+
120+
if (count($path) > 1) {
121+
if (array_key_exists($currentElement, $dca) && $dca[$currentElement]['inputType'] == 'multiColumnWizard') {
122+
$this->loadDcaSettingInDepth
123+
(
124+
$dcDriver,
125+
$dca[$currentElement]['eval']['columnFields'],
126+
array_slice($path, 2),
127+
$event
128+
);
129+
return;
130+
} else {
131+
// The path isn't a MCW element so someting is broken?
132+
throw new BadRequestHttpException('Bad request -- Got a MCW path, but can\'t be found');
133+
}
134+
} else {
135+
$mcwDca = $dca[$currentElement];
136+
$inputType = $mcwDca['inputType'];
137+
138+
/** @var string $widgetClassName */
139+
$widgetClassName = $GLOBALS['BE_FFL'][$inputType];
140+
141+
/** @var MultiColumnWizard $widget */
142+
/** @var MultiColumnWizard $widgetClassName */
143+
$widget = new $widgetClassName(
144+
$widgetClassName::getAttributesFromDca(
145+
$mcwDca,
146+
$currentElement,
147+
'',
148+
$fieldName,
149+
$dcDriver->table,
150+
$dcDriver
151+
)
152+
);
117153

118-
$event->setWidget($widget);
154+
// Set some more information.
155+
$widget->currentRecord = $dcDriver->id;
156+
$widget->activeRecord = $dcDriver->activeRecord;
157+
158+
$event->setWidget($widget);
159+
}
119160
}
120161

121162
/**
@@ -142,7 +183,7 @@ public function createWidgetDcGeneral(CreateWidgetEvent $event)
142183
}
143184

144185
// Trigger the dcg to generate the data.
145-
$env = $dcGeneral->getEnvironment();
186+
$env = $dcGeneral->getEnvironment();
146187
$model = $dcGeneral->getModel() ?: $dcGeneral
147188
->getEnvironment()
148189
->getDataProvider()

0 commit comments

Comments
 (0)