public function ConditionSetController::removeItem in Business Rules 8
Same name and namespace in other branches
- 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'
File
- src/
Controller/ ConditionSetController.php, line 300
Class
- ConditionSetController
- Class ConditionSetController.
Namespace
Drupal\business_rules\ControllerCode
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);
}
}