You are here

public function ConditionSetController::removeItem in Business Rules 8

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

Remove item from condition.

Parameters

string $condition_id: The condition id.

string $item_id: The item id.

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

Return value

\Drupal\Core\Ajax\AjaxResponse|\Symfony\Component\HttpFoundation\RedirectResponse The AjaxResponse or the RedirectResponse.

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

File

src/Controller/ConditionSetController.php, line 300

Class

ConditionSetController
Class ConditionSetController.

Namespace

Drupal\business_rules\Controller

Code

public function removeItem($condition_id, $item_id, $method) {
  $condition = Condition::load($condition_id);
  $items = $condition
    ->getSettings('items');
  unset($items[$item_id]);
  $items = is_null($items) ? [] : $items;
  $condition
    ->setSetting('items', $items);
  $condition
    ->save();
  if ($method == 'ajax') {
    $chart_definition = $this->util->flowchart
      ->getGraphDefinition($condition);
    $textarea = '<textarea id="graph_definition" style="display: none;">' . $chart_definition . '</textarea>';
    $response = new AjaxResponse();
    $response
      ->addCommand(new RemoveCommand('#' . $item_id));
    $response
      ->addCommand(new ReplaceCommand('#graph_definition', $textarea));
    $response
      ->addCommand(new UpdateFlowchartCommand());
    return $response;
  }
  else {
    $url = new Url('entity.business_rules_condition.edit_form', [
      'business_rule_condition' => $condition_id,
    ]);
    $string_url = $url
      ->toString() . '#business_rule-add_buttons';
    return new RedirectResponse($string_url);
  }
}