You are here

public function ConditionSetController::addItem in Business Rules 8

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

Add item on Condition.

Parameters

string $condition_id: The condition id.

string $item_id: The item.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse The RedirectResponse.

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

File

src/Controller/ConditionSetController.php, line 116

Class

ConditionSetController
Class ConditionSetController.

Namespace

Drupal\business_rules\Controller

Code

public function addItem($condition_id, $item_id) {
  $condition = Condition::load($condition_id);
  $weight = $this
    ->getMaxItemWeight($condition) + 1;
  $itemObj = new BusinessRulesItemObject($item_id, 'condition', $weight);
  $items = $condition
    ->getSettings('items');
  $item_array = $itemObj
    ->toArray();
  $items[$itemObj
    ->getId()] = $item_array[$itemObj
    ->getId()];
  $condition
    ->setSetting('items', $items);
  $condition
    ->save();
  $url = new Url('entity.business_rules_condition.edit_form', [
    'business_rules_condition' => $condition_id,
  ], [
    'fragment' => $item_id,
  ]);
  return new RedirectResponse($url
    ->toString());
}