You are here

public static function FillEntityVariableFields::removeFieldValue in Business Rules 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/BusinessRulesAction/FillEntityVariableFields.php \Drupal\business_rules\Plugin\BusinessRulesAction\FillEntityVariableFields::removeFieldValue()

Remove one field/value's setting.

Parameters

string $action: The action id.

string $field: The field id.

string $method: The method ajax|nojs.

Return value

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

1 string reference to 'FillEntityVariableFields::removeFieldValue'
business_rules.routing.yml in ./business_rules.routing.yml
business_rules.routing.yml

File

src/Plugin/BusinessRulesAction/FillEntityVariableFields.php, line 100

Class

FillEntityVariableFields
Class FillEntityVariableFields.

Namespace

Drupal\business_rules\Plugin\BusinessRulesAction

Code

public static function removeFieldValue($action, $field, $method) {
  $action = Action::load($action);
  $fields_values = $action
    ->getSettings('fields_values');
  unset($fields_values[$field]);
  $action
    ->setSetting('fields_values', $fields_values);
  $action
    ->save();
  if ($method == 'ajax') {
    $response = new AjaxResponse();
    $response
      ->addCommand(new RemoveCommand('#field_value-' . $field));
    return $response;
  }
  else {
    $url = new Url('entity.business_rules_action.edit_form', [
      'business_rules_action' => $action
        ->id(),
    ]);
    return new RedirectResponse($url
      ->toString());
  }
}