public function HideNotEmpty::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/ HideNotEmpty.php, line 24
Class
- HideNotEmpty
- The plugin for check not empty fields.
Namespace
Drupal\fico\Plugin\Field\FieldFormatter\ConditionCode
public function alterForm(&$form, $settings) {
$options = [];
$fields = $this
->getEntityFields($settings['entity_type'], $settings['bundle']);
$not_allowed = [
"list_string",
"boolean",
];
foreach ($fields as $field_name => $field) {
if ($field_name != $settings['field_name']) {
if (!in_array($field
->getType(), $not_allowed)) {
$options[$field_name] = $field
->getLabel();
}
}
}
$default_value = isset($settings['settings']['target_field']) ? $settings['settings']['target_field'] : NULL;
$form['target_field'] = [
'#type' => 'select',
'#title' => t('Field'),
'#options' => $options,
'#default_value' => $default_value,
];
}