You are here

public function LoopThroughViewResultController::removeItem in Business Rules 2.x

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

Remove item from condition.

Parameters

string $action_id: The action id.

string $item_type: The item type action|condition.

string $item_id: The item id.

string $method: The method name: ajax|nojs.

Return value

\Drupal\Core\Ajax\AjaxResponse|\Zend\Diactoros\Response\RedirectResponse The AjaxResponse or the RedirectResponse.

1 string reference to 'LoopThroughViewResultController::removeItem'
business_rules.routing.yml in ./business_rules.routing.yml
business_rules.routing.yml

File

src/Controller/LoopThroughViewResultController.php, line 313

Class

LoopThroughViewResultController
Class LoopThroughViewResultController.

Namespace

Drupal\business_rules\Controller

Code

public function removeItem($action_id, $item_type, $item_id, $method) {
  $action = Action::load($action_id);
  $items = $action
    ->getSettings('items');
  unset($items[$item_id]);
  $items = is_null($items) ? [] : $items;
  $action
    ->setSetting('items', $items);
  $action
    ->save();
  if ($method == 'ajax') {
    $response = new AjaxResponse();
    $response
      ->addCommand(new RemoveCommand('#' . $item_id));
    return $response;
  }
  else {
    $url = new Url('entity.business_rules_action.edit_form', [
      'business_rule_action' => $action_id,
    ]);
    $string_url = $url
      ->toString() . '#business_rule-add_buttons';
    return new RedirectResponse($string_url);
  }
}