Commit 6f98ec26605efc15d272f64d88d56d33928fdd61
1 parent
8720c989
Exists in
master
and in
64 other branches
Write argument item name in templated parameter (#5621 & #5671)
Showing
1 changed file
with
22 additions
and
7 deletions
Show diff stats
src/InputOutput/IHMImpl/Tools/IHMParamTemplateClass.php
... | ... | @@ -173,7 +173,7 @@ class IHMParamTemplateClass |
173 | 173 | if (!$templateHandle || !$dstHandle) |
174 | 174 | return ""; |
175 | 175 | while (($line = fgets($templateHandle)) !== false) { |
176 | - fwrite($dstHandle, $this->replaceArgs($line, $template_args)); | |
176 | + fwrite($dstHandle, $this->replaceArgs($line, $template_args, $this->getArguments($param_id))); | |
177 | 177 | } |
178 | 178 | fclose($templateHandle); |
179 | 179 | fclose($dstHandle); |
... | ... | @@ -218,10 +218,17 @@ class IHMParamTemplateClass |
218 | 218 | /* |
219 | 219 | * @brief Replace args in string |
220 | 220 | */ |
221 | - public function replaceArgs($string, $template_args) { | |
221 | + public function replaceArgs($string, $template_args, $arguments = array()) { | |
222 | 222 | $result = $string; |
223 | + if (empty($template_args)) { | |
224 | + return $result; | |
225 | + } | |
223 | 226 | foreach ($template_args as $template_arg_key => $template_arg_value) { |
224 | 227 | $result = str_replace("##".$template_arg_key."##", $template_arg_value, $result); |
228 | + if (array_key_exists($template_arg_key, $arguments) && ($arguments[$template_arg_key]['type'] == 'list')) { | |
229 | + $item_name = array_key_exists($template_arg_value, $arguments[$template_arg_key]['items']) ? $arguments[$template_arg_key]['items'][$template_arg_value] : 'Unknown'; | |
230 | + $result = str_replace("@@".$template_arg_key."@@", $item_name, $result); | |
231 | + } | |
225 | 232 | } |
226 | 233 | return $result; |
227 | 234 | } |
... | ... | @@ -230,17 +237,25 @@ class IHMParamTemplateClass |
230 | 237 | * @brief Enrich Template args with default values |
231 | 238 | */ |
232 | 239 | private function addDefaultValues($param_id, &$template_args) { |
233 | - $list = $this->getParamTemplates(); | |
234 | - | |
235 | - if (!array_key_exists($param_id, $list)) | |
240 | + $arguments = $this->getArguments($param_id); | |
241 | + if (empty($arguments)) | |
236 | 242 | return; |
237 | - | |
238 | - $arguments = $list[$param_id]->arguments; | |
239 | 243 | foreach ($arguments as $arg_key => $arg_def) { |
240 | 244 | if (!array_key_exists($arg_key, $template_args)) |
241 | 245 | $template_args[$arg_key] = $arg_def->default; |
242 | 246 | } |
243 | 247 | } |
248 | + | |
249 | + /* | |
250 | + * @brief Get list of arguments for a given parameter | |
251 | + */ | |
252 | + protected function getArguments($param_id) { | |
253 | + $list = $this->getParamTemplates(); | |
254 | + | |
255 | + if (!array_key_exists($param_id, $list) || !isset($list[$param_id]['arguments'])) | |
256 | + return array(); | |
257 | + return $list[$param_id]['arguments']; | |
258 | + } | |
244 | 259 | |
245 | 260 | /* |
246 | 261 | * @brief Load list of templated parameters |
... | ... |