public function ConditionForm::save in Business Rules 2.x
Same name and namespace in other branches
- 8 src/Form/ConditionForm.php \Drupal\business_rules\Form\ConditionForm::save()
Additional steps to save condition's items.
Overrides ItemForm::save
File
- src/
Form/ ConditionForm.php, line 334
Class
- ConditionForm
- Class ConditionForm.
Namespace
Drupal\business_rules\FormCode
public function save(array $form, FormStateInterface $form_state) {
/** @var \Drupal\business_rules\Entity\Condition $condition */
$condition = $this->entity;
if (!$condition
->isNew()) {
$success_items = $form_state
->getValue('success');
$fail_items = $form_state
->getValue('fail');
$condition
->set('success_items', []);
$condition
->set('fail_items', []);
$new_success_items = [];
$new_fail_items = [];
if (is_array($success_items)) {
foreach ($success_items as $key => $value) {
$itemObj = new BusinessRulesItemObject($key, $value['business_rule_item_type'], $value['weight']);
$new_success_items[$value['weight']] = $itemObj;
}
}
if (is_array($fail_items)) {
foreach ($fail_items as $key => $value) {
$itemObj = new BusinessRulesItemObject($key, $value['business_rule_item_type'], $value['weight']);
$new_fail_items[$value['weight']] = $itemObj;
}
}
ksort($new_success_items);
foreach ($new_success_items as $item) {
$condition
->addSuccessItem($item);
}
ksort($new_fail_items);
foreach ($new_fail_items as $item) {
$condition
->addFailItem($item);
}
$condition
->save();
}
return parent::save($form, $form_state);
}