public function BusinessRulesItemsController::addItem in Business Rules 8
Same name and namespace in other branches
- 2.x src/Controller/BusinessRulesItemsController.php \Drupal\business_rules\Controller\BusinessRulesItemsController::addItem()
Add one item on the Business Rule.
Parameters
string $business_rule: The business rule id.
string $item_type: The item type.
string $item_id: The item id.
Return value
\Symfony\Component\HttpFoundation\RedirectResponse The RedirectResponse.
1 string reference to 'BusinessRulesItemsController::addItem'
File
- src/
Controller/ BusinessRulesItemsController.php, line 134
Class
- BusinessRulesItemsController
- Class BusinessRulesItemsController.
Namespace
Drupal\business_rules\ControllerCode
public function addItem($business_rule, $item_type, $item_id) {
$rule = BusinessRule::load($business_rule);
$weight = $rule
->getItemMaxWeight() + 1;
$itemObj = new BusinessRulesItemObject($item_id, $item_type, $weight);
$rule
->addItem($itemObj);
$rule
->save();
$url = new Url('entity.business_rule.edit_form', [
'business_rule' => $business_rule,
]);
$string_url = $url
->toString() . '#' . $item_id;
return new RedirectResponse($string_url);
}