You are here

public function LoopThroughViewResultController::addItem in Business Rules 8

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

Add item on Action.

Parameters

string $action_id: The action id.

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 'LoopThroughViewResultController::addItem'
business_rules.routing.yml in ./business_rules.routing.yml
business_rules.routing.yml

File

src/Controller/LoopThroughViewResultController.php, line 108

Class

LoopThroughViewResultController
Class LoopThroughViewResultController.

Namespace

Drupal\business_rules\Controller

Code

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