You are here

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

Class

HideIfAuthor
The plugin for check empty fields.

Namespace

Drupal\fico\Plugin\Field\FieldFormatter\Condition

Code

public function alterForm(&$form, $settings) {
  if (isset($settings['settings']['author'])) {
    $user = User::load($settings['settings']['author']);
  }
  else {
    $user = NULL;
  }
  $config = \Drupal::config('user.settings');
  $form['author'] = array(
    '#title' => t('Authored by'),
    '#type' => 'entity_autocomplete',
    '#target_type' => 'user',
    '#selection_settings' => [
      'include_anonymous' => FALSE,
    ],
    '#description' => t('Leave blank for %anonymous.', [
      '%anonymous' => $config
        ->get('anonymous'),
    ]),
    '#default_value' => $user,
  );
}