Skip to content

Commit

Permalink
Dev: EM events fix for default values (#1411)
Browse files Browse the repository at this point in the history
Dev: default values are taken too for empty arrays, then :
Dev: set default to empty array when needed
  • Loading branch information
Shnoulle committed Apr 27, 2020
1 parent 2c1a4bd commit 3e78299
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
4 changes: 2 additions & 2 deletions application/helpers/expressions/em_core_helper.php
Expand Up @@ -290,8 +290,8 @@ public function ExpressionManagerStartEvent()

$event = new \LimeSurvey\PluginManager\PluginEvent('ExpressionManagerStart');
$result = App()->getPluginManager()->dispatchEvent($event);
$newValidFunctions = (array) $result->get('functions');
$newPackages = (array) $result->get('packages'); // package added to expression-extend['depends'] : maybe don't add it in event, but add an helper ?
$newValidFunctions = $result->get('functions',array());
$newPackages = $result->get('packages',array()); // package added to expression-extend['depends'] : maybe don't add it in event, but add an helper ?
$this->RegisterFunctions($newValidFunctions); // No validation : plugin dev can break all easily
foreach($newPackages as $name => $definition) {
Expand Down
17 changes: 5 additions & 12 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -4409,20 +4409,13 @@ public function setVariableAndTokenMappingsForExpressionManager($surveyid,$force
$event->set('questionSeq2relevance',$this->questionSeq2relevance);
$event->set('newExpressionSuffixes',array());
$result = App()->getPluginManager()->dispatchEvent($event);
$newExpressionSuffixes = $event->get('newExpressionSuffixes');
if(!empty($newExpressionSuffixes)) { /* Don't add if it's null */
$this->em->addRegexpExtraAttributes($newExpressionSuffixes);
}
$this->em->addRegexpExtraAttributes($event->get('newExpressionSuffixes', array()));
/* Put in manual : offer updating this part must be done with care. And can broke without API version update */
$this->knownVars = $result->get('knownVars');
$this->questionSeq2relevance = $result->get('questionSeq2relevance');
$this->knownVars = $result->get('knownVars', array()); // PluginManager use not a strict compare to false, empty array get the default.
$this->questionSeq2relevance = $result->get('questionSeq2relevance', array()); // PluginManager use not a strict compare to false, empty array get the default.
$this->runtimeTimings[] = array(__METHOD__ . ' - process fieldMap',(microtime(true) - $now));
if (!empty($this->questionSeq2relevance)) {
usort($this->questionSeq2relevance,'cmpQuestionSeq');
$this->numQuestions = count($this->questionSeq2relevance);
} else {
$this->numQuestions = 0;
}
usort($this->questionSeq2relevance,'cmpQuestionSeq');
$this->numQuestions = count($this->questionSeq2relevance);
$this->numGroups = count($this->groupSeqInfo);
return true;
}
Expand Down

0 comments on commit 3e78299

Please sign in to comment.