@@ -93,23 +93,23 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
9393 // $regexPattern match on: $matches[0] {{section.element(arg.field)}}
9494 // $matches[1] = section.element
9595 // $matches[2] = arg.field
96- $ regexPattern = '/{{([\w.\[\]]+)\(*([\w.$ \']+)*\)*}}/ ' ;
96+ $ regexPattern = '/{{([\w.\[\]]+)\(*([\w.$ \',\s ]+)*\)*}}/ ' ;
9797
9898 foreach ($ this ->parsedActions as $ action ) {
9999 $ varAttributes = array_intersect ($ this ->varAttributes , array_keys ($ action ->getCustomActionAttributes ()));
100100 $ newActionAttributes = [];
101+
101102 if (!empty ($ varAttributes )) {
102103 // 1 check to see if we have pertinent var
103104 foreach ($ varAttributes as $ varAttribute ) {
104105 $ attributeValue = $ action ->getCustomActionAttributes ()[$ varAttribute ];
105106 preg_match_all ($ regexPattern , $ attributeValue , $ matches );
106-
107107 if (empty ($ matches [0 ])) {
108108 continue ;
109109 }
110110
111111 //get rid of full match {{arg.field(arg.field)}}
112- unset ($ matches[ 0 ] );
112+ array_shift ($ matches );
113113
114114 $ newActionAttributes [$ varAttribute ] = $ this ->replaceAttributeArguments (
115115 $ arguments ,
@@ -141,36 +141,68 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
141141 */
142142 private function replaceAttributeArguments ($ arguments , $ attributeValue , $ matches )
143143 {
144- $ matchParametersKey = 2 ;
145- $ newAttributeVal = $ attributeValue ;
144+ list ($ mainValueList , $ possibleArgumentsList ) = $ matches ;
146145
147- foreach ($ matches as $ key => $ match ) {
148- foreach ($ match as $ variable ) {
149- if (empty ($ variable )) {
150- continue ;
151- }
152- // Truncate arg.field into arg. If 'Literal' was passed, variableName will be null.
153- $ variableName = strstr ($ variable , '. ' , true );
154- // Check if arguments has a mapping for the given variableName
155- if ($ variableName == null || !array_key_exists ($ variableName , $ arguments )) {
156- continue ;
157- }
158- $ isPersisted = strstr ($ arguments [$ variableName ], '$ ' );
159- if ($ isPersisted ) {
160- $ newAttributeVal = $ this ->replacePersistedArgument (
161- $ arguments [$ variableName ],
162- $ attributeValue ,
163- $ variable ,
164- $ variableName ,
165- $ key == $ matchParametersKey ? true : false
166- );
167- } else {
168- $ newAttributeVal = str_replace ($ variableName , $ arguments [$ variableName ], $ attributeValue );
169- }
146+ foreach ($ mainValueList as $ index => $ mainValue ) {
147+ $ possibleArguments = $ possibleArgumentsList [$ index ];
148+
149+ $ attributeValue = $ this ->replaceAttributeArgumentInVariable ($ mainValue , $ arguments , $ attributeValue );
150+
151+ // Split on commas, trim all values, and finally filter out all FALSE values
152+ $ argumentList = array_filter (array_map ('trim ' , explode (', ' , $ possibleArguments )));
153+
154+ foreach ($ argumentList as $ argumentValue ) {
155+ $ attributeValue = $ this ->replaceAttributeArgumentInVariable (
156+ $ argumentValue ,
157+ $ arguments ,
158+ $ attributeValue ,
159+ true
160+ );
170161 }
171162 }
172163
173- return $ newAttributeVal ;
164+ return $ attributeValue ;
165+ }
166+
167+ /**
168+ * Replace attribute arguments in variable.
169+ *
170+ * @param string $variable
171+ * @param array $arguments
172+ * @param string $attributeValue
173+ * @param bool $isInnerArgument
174+ * @return string
175+ */
176+ private function replaceAttributeArgumentInVariable (
177+ $ variable ,
178+ $ arguments ,
179+ $ attributeValue ,
180+ $ isInnerArgument = false
181+ ) {
182+ // Truncate arg.field into arg
183+ $ variableName = strstr ($ variable , '. ' , true );
184+ // Check if arguments has a mapping for the given variableName
185+
186+ if ($ variableName === false ) {
187+ $ variableName = $ variable ;
188+ }
189+
190+ if (!array_key_exists ($ variableName , $ arguments )) {
191+ return $ attributeValue ;
192+ }
193+
194+ $ isPersisted = strstr ($ arguments [$ variableName ], '$ ' );
195+ if ($ isPersisted ) {
196+ return $ this ->replacePersistedArgument (
197+ $ arguments [$ variableName ],
198+ $ attributeValue ,
199+ $ variable ,
200+ $ variableName ,
201+ $ isInnerArgument
202+ );
203+ }
204+
205+ return str_replace ($ variableName , $ arguments [$ variableName ], $ attributeValue );
174206 }
175207
176208 /**
@@ -197,11 +229,12 @@ private function replacePersistedArgument($replacement, $attributeValue, $fullVa
197229
198230 // parameter replacements require changing of (arg.field) to ($arg.field$)
199231 if ($ isParameter ) {
200- $ newAttributeValue = str_replace ($ fullVariable , $ scope . $ fullVariable . $ scope , $ newAttributeValue );
232+ $ fullReplacement = str_replace ($ variable , trim ($ replacement , '$ ' ), $ fullVariable );
233+ $ newAttributeValue = str_replace ($ fullVariable , $ scope . $ fullReplacement . $ scope , $ newAttributeValue );
201234 } else {
202235 $ newAttributeValue = str_replace ('{{ ' , $ scope , str_replace ('}} ' , $ scope , $ newAttributeValue ));
236+ $ newAttributeValue = str_replace ($ variable , trim ($ replacement , '$ ' ), $ newAttributeValue );
203237 }
204- $ newAttributeValue = str_replace ($ variable , trim ($ replacement , '$ ' ), $ newAttributeValue );
205238
206239 return $ newAttributeValue ;
207240 }
0 commit comments