You are here

public function ConditionsItemsController::addItem in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Controller/ConditionsItemsController.php \Drupal\business_rules\Controller\ConditionsItemsController::addItem()

Add item on Condition.

Parameters

string $condition_id: The condition id.

string $condition_item_type: The condition item type: success|fail.

string $item_type: The item type action|condition.

string $item_id: The item id.

Return value

\Zend\Diactoros\Response\RedirectResponse The RedirectResponse.

1 string reference to 'ConditionsItemsController::addItem'
business_rules.routing.yml in ./business_rules.routing.yml
business_rules.routing.yml

File

src/Controller/ConditionsItemsController.php, line 119

Class

ConditionsItemsController
Class ConditionsItemsController.

Namespace

Drupal\business_rules\Controller

Code

public function addItem($condition_id, $condition_item_type, $item_type, $item_id) {
  $condition = Condition::load($condition_id);
  $weight = $condition
    ->getMaxItemWeight($condition_item_type == 'success') + 1;
  $itemObj = new BusinessRulesItemObject($item_id, $item_type, $weight);
  if ($condition_item_type == 'success') {
    $condition
      ->addSuccessItem($itemObj);
  }
  else {
    $condition
      ->addFailItem($itemObj);
  }
  $condition
    ->save();
  $url = new Url('entity.business_rules_condition.edit_form', [
    'business_rules_condition' => $condition_id,
  ], [
    'fragment' => $condition_item_type . '-' . $item_id,
  ]);
  return new RedirectResponse($url
    ->toString());
}