You are here

public function ConditionsItemsController::removeItem in Business Rules 8

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

Remove item from 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.

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

File

src/Controller/ConditionsItemsController.php, line 319

Class

ConditionsItemsController
Class ConditionsItemsController.

Namespace

Drupal\business_rules\Controller

Code

public function removeItem($condition_id, $condition_item_type, $item_type, $item_id, $method) {
  $condition = Condition::load($condition_id);
  $itemObj = new BusinessRulesItemObject($item_id, $item_type, 0);
  if ($condition_item_type == 'success') {
    $condition
      ->removeSuccessItem($itemObj);
  }
  else {
    $condition
      ->removeFailItem($itemObj);
  }
  $condition
    ->save();
  if ($method == 'ajax') {
    $chart_definition = $this->flowchart
      ->getGraphDefinition($condition);
    $textarea = '<textarea id="graph_definition" style="display: none;">' . $chart_definition . '</textarea>';
    $response = new AjaxResponse();
    $response
      ->addCommand(new RemoveCommand('#' . $condition_item_type . '-' . $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() . '#' . $condition_item_type . '-business_rule-add_buttons';
    return new RedirectResponse($string_url);
  }
}