public function SubmitButtonRules::formSubmitRules in Flexiform 8
Fire rules component on submit.
File
- contrib/
rules/ src/ Plugin/ FormEnhancer/ SubmitButtonRules.php, line 314
Class
- SubmitButtonRules
- A flexiform enhancer to trigger rules on submission.
Namespace
Drupal\flexiform_rules\Plugin\FormEnhancerCode
public function formSubmitRules($form, FormStateInterface $form_state) {
$button = $form_state
->getTriggeringElement();
$rules = $button['#submit_rules'];
uasort($rules, [
SortArray::class,
'sortByWeightElement',
]);
foreach ($rules as $rule_name => $info) {
$rule = $this
->rulesStorage()
->load($rule_name);
// Prepare arguments for rule execution.
$arguments = $this->formDisplay
->getFormEntityManager()
->getFormEntities();
if ($this->formDisplay
->getBaseEntityNamespace() == '' && isset($arguments[''])) {
$arguments['base_entity'] = $argumets[''];
unset($arguments['']);
}
// Fire the rule.
$rule
->getComponent()
->executeWithArguments($arguments);
}
}