function BooleanFormatter::getOutputFormats

Same name in other branches
  1. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\BooleanFormatter::getOutputFormats()
  2. 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\BooleanFormatter::getOutputFormats()
  3. 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\BooleanFormatter::getOutputFormats()

Gets the available format options.

Return value

array|string A list of output formats. Each entry is keyed by the machine name of the format. The value is an array, of which the first item is the result for boolean TRUE, the second is for boolean FALSE. The value can be also an array, but this is just the case for the custom format.

3 calls to BooleanFormatter::getOutputFormats()
BooleanFormatter::settingsForm in core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php
Returns a form to configure settings for the formatter.
BooleanFormatter::settingsSummary in core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php
Returns a short summary for the current formatter settings.
BooleanFormatter::viewElements in core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php
Builds a renderable array for a field value.

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php, line 46

Class

BooleanFormatter
Plugin implementation of the 'boolean' formatter.

Namespace

Drupal\Core\Field\Plugin\Field\FieldFormatter

Code

protected function getOutputFormats() {
    $formats = [
        'default' => [
            $this->getFieldSetting('on_label'),
            $this->getFieldSetting('off_label'),
        ],
        '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' => [
            '✔',
            '✖',
        ],
        'custom' => $this->t('Custom'),
    ];
    return $formats;
}

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