Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Boolean.php

function 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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal