You are here

public function CompareNumberOfResultsBetweenTwoViews::getSettingsForm in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Plugin/BusinessRulesCondition/CompareNumberOfResultsBetweenTwoViews.php \Drupal\business_rules\Plugin\BusinessRulesCondition\CompareNumberOfResultsBetweenTwoViews::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/CompareNumberOfResultsBetweenTwoViews.php, line 34

Class

CompareNumberOfResultsBetweenTwoViews
Class CompareNumberOfResultsBetweenTwoViews.

Namespace

Drupal\business_rules\Plugin\BusinessRulesCondition

Code

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

  // Only present the settings form if the condition is already saved.
  if ($item
    ->isNew()) {
    return [];
  }
  $settings['view_1'] = [
    '#type' => 'select',
    '#title' => t('First view. View name : Display mode id : Display mode title.'),
    '#options' => $this->util
      ->getViewsOptions(),
    '#required' => TRUE,
    '#default_value' => $item
      ->getSettings('view_1'),
    '#description' => t('Select the view to compare the number of results.'),
  ];
  $settings['arguments_1'] = [
    '#type' => 'textarea',
    '#title' => t('Arguments for view 1'),
    '#description' => t('Any argument the first view may need, one per line. Be aware of including them at same order as the CONTEXTUAL FILTERS configured in the view. You may use variables.'),
    '#default_value' => $item
      ->getSettings('arguments_1'),
  ];
  $settings['operator'] = [
    '#type' => 'select',
    '#title' => t('Comparator'),
    '#description' => t('The operator to compare the result between the views.'),
    '#required' => TRUE,
    '#options' => [
      '==' => '=',
      '>' => '>',
      '>=' => '>=',
      '<' => '<',
      '<=' => '<=',
      '!=' => '!=',
    ],
    '#default_value' => $item
      ->getSettings('operator'),
  ];
  $settings['view_2'] = [
    '#type' => 'select',
    '#title' => t('Second view. View name : Display mode id : Display mode title.'),
    '#options' => $this->util
      ->getViewsOptions(),
    '#required' => TRUE,
    '#default_value' => $item
      ->getSettings('view_2'),
    '#description' => t('Select the view to compare the number of results.'),
  ];
  $settings['arguments_2'] = [
    '#type' => 'textarea',
    '#title' => t('Arguments for view 2'),
    '#description' => t('Any argument the second view may need, one per line. Be aware of including them at same order as the CONTEXTUAL FILTERS configured in the view. You may use variables.'),
    '#default_value' => $item
      ->getSettings('arguments_2'),
  ];
  return $settings;
}