You are here

public function HideNoString::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/HideNoString.php, line 23

Class

HideNoString
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']);
  $allowed_field_types = fico_text_types();
  foreach ($fields as $field_name => $field) {
    if ($field_name != $settings['field_name'] && in_array($field
      ->getType(), $allowed_field_types)) {
      $options[$field_name] = $field
        ->getLabel();
    }
  }
  $default_target = isset($settings['settings']['target_field']) ? $settings['settings']['target_field'] : NULL;
  $form['target_field'] = [
    '#type' => 'select',
    '#title' => t('Select target field'),
    '#options' => $options,
    '#default_value' => $default_target,
  ];
  $default_string = isset($settings['settings']['string']) ? $settings['settings']['string'] : NULL;
  $form['string'] = array(
    '#type' => 'textfield',
    '#title' => t('Enter target string'),
    '#default_value' => $default_string,
  );
}