You are here

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

Class

HideOnRole
The plugin for check empty fields.

Namespace

Drupal\fico\Plugin\Field\FieldFormatter\Condition

Code

public function alterForm(&$form, $settings) {
  $user_roles = [];
  foreach (Role::loadMultiple() as $role) {
    $user_roles[$role
      ->id()] = $role
      ->label();
  }
  $default_include = isset($settings['settings']['include_admin']) ? $settings['settings']['include_admin'] : NULL;
  $default_roles = isset($settings['settings']['roles']) ? $settings['settings']['roles'] : NULL;
  $form['include_admin'] = array(
    '#type' => 'checkbox',
    '#title' => t('Include the administrator'),
    '#default_value' => $default_include,
  );
  $form['roles'] = array(
    '#type' => 'select',
    '#multiple' => TRUE,
    '#title' => t('Select roles'),
    '#options' => $user_roles,
    '#default_value' => $default_roles,
  );
}