function Boolean::init

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/field/Boolean.php \Drupal\views\Plugin\views\field\Boolean::init()
  2. 8.9.x core/modules/views/src/Plugin/views/field/Boolean.php \Drupal\views\Plugin\views\field\Boolean::init()
  3. 11.x core/modules/views/src/Plugin/views/field/Boolean.php \Drupal\views\Plugin\views\field\Boolean::init()

Overrides FieldPluginBase::init

File

core/modules/views/src/Plugin/views/field/Boolean.php, line 53

Class

Boolean
A handler to provide proper displays for booleans.

Namespace

Drupal\views\Plugin\views\field

Code

public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) {
  parent::init($view, $display, $options);
  $default_formats = [
    'yes-no' => [
      $this->t('Yes'),
      $this->t('No'),
    ],
    'true-false' => [
      $this->t('True'),
      $this->t('False'),
    ],
    'on-off' => [
      $this->t('On'),
      $this->t('Off'),
    ],
    'enabled-disabled' => [
      $this->t('Enabled'),
      $this->t('Disabled'),
    ],
    'boolean' => [
      1,
      0,
    ],
    'unicode-yes-no' => [
      '✔',
      '✖',
    ],
  ];
  $output_formats = $this->definition['output formats'] ?? [];
  $custom_format = [
    'custom' => [
      $this->t('Custom'),
    ],
  ];
  $this->formats = array_merge($default_formats, $output_formats, $custom_format);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.