You are here

public function BusinessRuleForm::getEntityInformationForm in Business Rules 8

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

Get the fields for entity type and bundle.

Parameters

array $rule_definition: The rule definition.

Return value

array The render array.

1 call to BusinessRuleForm::getEntityInformationForm()
BusinessRuleForm::form in src/Form/BusinessRuleForm.php
Gets the actual form array to be built.

File

src/Form/BusinessRuleForm.php, line 203

Class

BusinessRuleForm
Class BusinessRuleForm.

Namespace

Drupal\business_rules\Form

Code

public function getEntityInformationForm(array $rule_definition) {
  $form = [];

  /** @var \Drupal\business_rules\BusinessRuleInterface $rule */
  $rule = $this->entity;
  $show_entity = FALSE;
  $show_bundle = FALSE;
  if ($rule_definition['hasTargetBundle']) {
    $show_entity = TRUE;
    $show_bundle = TRUE;
  }
  elseif ($rule_definition['hasTargetEntity']) {
    $show_entity = TRUE;
  }
  if ($show_entity) {
    $form['context'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Context: This information cannot be changed after the business rule is saved.'),
    ];
    $form['context']['target_entity_type'] = [
      '#type' => 'select',
      '#options' => $this->util
        ->getEntityTypes(),
      '#required' => TRUE,
      '#title' => $this
        ->t('Target Entity Type'),
      '#description' => $this
        ->t('The Entity Type which this business rule is applicable.'),
      '#default_value' => $rule
        ->getTargetEntityType(),
      '#disabled' => $this->entity
        ->isNew() ? FALSE : TRUE,
    ];
  }
  if ($show_bundle) {
    $form['context']['target_entity_type']['#ajax'] = [
      'callback' => [
        $this,
        'targetEntityTypeCallback',
      ],
    ];
    $form['context']['target_bundle'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Target Bundle'),
      '#description' => $this
        ->t('The Bundle which this business rule is applicable.'),
      '#options' => $this->util
        ->getBundles($rule
        ->getTargetEntityType()),
      '#required' => TRUE,
      '#default_value' => $rule
        ->getTargetBundle(),
      '#disabled' => $this->entity
        ->isNew() ? FALSE : TRUE,
      '#prefix' => '<div id="target_bundle-wrapper">',
      '#suffix' => '</div>',
    ];
  }
  return $form;
}