You are here

public function HideIfBoolCheck::alterForm in Field Formatter Condition 8

Alter the condition form.

Parameters

array $form: Condition formular.

array $settings: Settings array.

Overrides FieldFormatterConditionBase::alterForm

File

src/Plugin/Field/FieldFormatter/Condition/HideIfBoolCheck.php, line 23

Class

HideIfBoolCheck
The plugin for check empty fields.

Namespace

Drupal\fico\Plugin\Field\FieldFormatter\Condition

Code

public function alterForm(&$form, $settings) {
  $options = [];
  $fields = $this
    ->getEntityFields($settings['entity_type'], $settings['bundle']);
  foreach ($fields as $field_name => $field) {
    if ($field_name != $settings['field_name'] && $field
      ->getType() == 'boolean') {
      $options[$field_name] = $field
        ->getLabel();
    }
  }
  $default_target_field = isset($settings['settings']['target_field']) ? $settings['settings']['target_field'] : NULL;
  $form['target_field'] = [
    '#type' => 'select',
    '#title' => t('Field'),
    '#options' => $options,
    '#default_value' => $default_target_field,
    '#required' => TRUE,
  ];
  $default_negate = isset($settings['settings']['negate']) ? $settings['settings']['negate'] : NULL;
  $form['negate'] = [
    '#type' => 'checkbox',
    '#title' => t('Negate'),
    '#description' => t('If checked, the condition result is negated such that it returns TRUE if it evaluates to FALSE.'),
    '#default_value' => $default_negate,
  ];
}