You are here

public static function ChangeFieldInfo::removeField in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Plugin/BusinessRulesAction/ChangeFieldInfo.php \Drupal\business_rules\Plugin\BusinessRulesAction\ChangeFieldInfo::removeField()

Remove one field from the action.

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 response.

1 string reference to 'ChangeFieldInfo::removeField'
business_rules.routing.yml in ./business_rules.routing.yml
business_rules.routing.yml

File

src/Plugin/BusinessRulesAction/ChangeFieldInfo.php, line 115

Class

ChangeFieldInfo
Class ChangeFieldInfo.

Namespace

Drupal\business_rules\Plugin\BusinessRulesAction

Code

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