You are here

public function DataComparison::getSettingsForm in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Plugin/BusinessRulesCondition/DataComparison.php \Drupal\business_rules\Plugin\BusinessRulesCondition\DataComparison::getSettingsForm()

Return the form array.

@internal param array $form

Parameters

array $form: The form array.

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

\Drupal\business_rules\ItemInterface $item: The configured item.

Return value

array The render array for the settings form.

Overrides BusinessRulesItemPluginBase::getSettingsForm

File

src/Plugin/BusinessRulesCondition/DataComparison.php, line 39

Class

DataComparison
Class DataComparison.

Namespace

Drupal\business_rules\Plugin\BusinessRulesCondition

Code

public function getSettingsForm(array &$form, FormStateInterface $form_state, ItemInterface $condition) {

  // Only show settings form if the item is already saved.
  if ($condition
    ->isNew()) {
    return [];
  }
  $settings['data_to_compare'] = [
    '#type' => 'select',
    '#title' => t('Data to compare'),
    '#required' => TRUE,
    '#options' => [
      '' => t('- Select -'),
      self::CURRENT_DATA => t('Current value'),
      self::ORIGINAL_DATA => t('Original value'),
    ],
    '#description' => t('Current value is the value that is being saved.') . '<br>' . t('Original value is the previous saved value.'),
    '#default_value' => empty($condition
      ->getSettings('data_to_compare')) ? '' : $condition
      ->getSettings('data_to_compare'),
  ];
  $settings['operator'] = [
    '#type' => 'select',
    '#required' => TRUE,
    '#title' => t('Operator'),
    '#description' => t('The operation to be performed on this data comparison.'),
    '#default_value' => $condition
      ->getSettings('operator'),
    '#options' => $this->util
      ->getCriteriaMetOperatorsOptions(),
  ];
  $settings['value_to_compare'] = [
    '#title' => t('Value to compare'),
    '#default_value' => $condition
      ->getSettings('value_to_compare'),
    '#type' => 'textarea',
    '#description' => t('For multiple values comparison, include one per line.
        It will return TRUE if at least one element was found.
        <br>If the comparison field is a list of values, enter the element(s) id(s)
        <br>Enter the element(s) id(s), one per line.
        <br>To use variables, just type the variable machine name as {{variable_id}}. If the variable is an Entity Variable, you can access the fields values using {{variable_id->field}}'),
    '#states' => [
      'invisible' => [
        'select[name="operator"]' => [
          'value' => 'empty',
        ],
      ],
    ],
  ];
  return $settings;
}