1111
1212namespace MultiColumnWizard \DcGeneral ;
1313
14- use ContaoCommunityAlliance \DcGeneral \Contao \View \Contao2BackendView \Event \BuildWidgetEvent ;
1514use ContaoCommunityAlliance \DcGeneral \DataDefinition \Definition \Properties \DefaultProperty ;
16- use ContaoCommunityAlliance \DcGeneral \EnvironmentInterface ;
17- use ContaoCommunityAlliance \DcGeneral \Factory \Event \PopulateEnvironmentEvent ;
15+ use ContaoCommunityAlliance \DcGeneral \Factory \Event \BuildDataDefinitionEvent ;
1816
1917/**
2018 * Class UpdateDataDefinition
2119 *
22- * @author Sven Baumann <baumann.sv@gmail.com> 2017
23- * @package MultiColumnWizard\DcGeneral
20+ * @package MultiColumnWizard\DcGeneral
2421 */
2522class UpdateDataDefinition
2623{
27- const POPULATE_PRIORITY = -500000 ;
28- const BUILD_WIDGET_PRIORITY = 500000 ;
24+ const PRIORITY = -500000 ;
2925
3026 /**
3127 * Add all fields from the MCW to the DCA. This is needed for some fields, because other components need this
3228 * to create the widget/view etc.
3329 *
34- * @param PopulateEnvironmentEvent $event
30+ * @param BuildDataDefinitionEvent $event
3531 *
3632 * @return void
3733 */
38- public function addMcwFields (PopulateEnvironmentEvent $ event )
34+ function addMcwFields (BuildDataDefinitionEvent $ event )
3935 {
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 ();
36+ // Get the container and all properties.
37+ $ container = $ event ->getContainer ();
38+ $ properties = $ container ->getPropertiesDefinition ();
9139
9240 /** @var DefaultProperty $property */
9341 foreach ($ properties as $ property ) {
@@ -100,20 +48,16 @@ private function buildProperty($propertyName, EnvironmentInterface $environment)
10048 $ config = $ property ->getExtra ();
10149
10250 // If we have no data here, go to the next.
103- if (empty ($ config ['columnFields ' ]) || !is_array ($ config ['columnFields ' ])) {
51+ if (empty ($ config ['columnFields ' ]) || !is_array ($ config ['columnFields ' ])){
10452 continue ;
10553 }
10654
10755 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- }
56+ // Build the default name.
57+ $ name = sprintf ('%s__%s ' , $ property ->getName (), $ fieldKey );
11458
11559 // Make a new field and fill it with the data from the config.
116- $ subProperty = new DefaultProperty ($ propertyName );
60+ $ subProperty = new DefaultProperty ($ name );
11761 foreach ($ fieldConfig as $ key => $ value ) {
11862 switch ($ key ) {
11963 case 'label ' :
@@ -133,15 +77,15 @@ private function buildProperty($propertyName, EnvironmentInterface $environment)
13377 break ;
13478
13579 case 'exclude ' :
136- $ subProperty ->setExcluded ((bool ) $ value );
80+ $ subProperty ->setExcluded ((bool )$ value );
13781 break ;
13882
13983 case 'search ' :
140- $ subProperty ->setSearchable ((bool ) $ value );
84+ $ subProperty ->setSearchable ((bool )$ value );
14185 break ;
14286
14387 case 'filter ' :
144- $ subProperty ->setFilterable ((bool ) $ value );
88+ $ subProperty ->setFilterable ((bool )$ value );
14589 break ;
14690
14791 case 'inputType ' :
@@ -178,57 +122,10 @@ private function buildProperty($propertyName, EnvironmentInterface $environment)
178122 }
179123 }
180124
125+ // Add all to the current list.
181126 $ 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 ;
187127 }
188128 }
189- }
190-
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 ();
201-
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 ' );
230- }
231129
232- return '' ;
233130 }
234131}
0 commit comments