You are here

public function ItemForm::targetBundleCallback in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Form/ItemForm.php \Drupal\business_rules\Form\ItemForm::targetBundleCallback()

Helper function to show the list of fields according the selected Bundle.

Parameters

array $form: The form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

Return value

\Drupal\Core\Ajax\AjaxResponse The AjaxResponse.

File

src/Form/ItemForm.php, line 514

Class

ItemForm
Base class for Business rules item.

Namespace

Drupal\business_rules\Form

Code

public function targetBundleCallback(array &$form, FormStateInterface $form_state) {
  $selected_bundle = $form_state
    ->getValue('target_bundle');
  $selected_entity_type = $form_state
    ->getValue('target_entity_type');
  $field =& $form['settings']['field'];
  $field['#options'] = $this->util
    ->getBundleFields($selected_entity_type, $selected_bundle);
  $field['#default_value'] = '';
  $response = new AjaxResponse();
  $response
    ->addCommand(new ReplaceCommand('#field_selector-wrapper', $field));
  $form_state
    ->setRebuild();
  return $response;
}