You are here

public function BusinessRulesItemsController::addItem in Business Rules 2.x

Same name and namespace in other branches
  1. 8 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'
business_rules.routing.yml in ./business_rules.routing.yml
business_rules.routing.yml

File

src/Controller/BusinessRulesItemsController.php, line 134

Class

BusinessRulesItemsController
Class BusinessRulesItemsController.

Namespace

Drupal\business_rules\Controller

Code

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);
}