class OptionsDefaultFormatter

Plugin implementation of the 'list_default' formatter.

Plugin annotation


@FieldFormatter(
  id = "list_default",
  module = "options",
  label = @Translation("Default"),
  field_types = {
    "list_integer",
    "list_float",
    "list_text",
    "list_boolean"
  }
)

Hierarchy

Expanded class hierarchy of OptionsDefaultFormatter

File

drupal/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsDefaultFormatter.php, line 30
Contains \Drupal\options\Plugin\field\formatter\OptionsDefaultFormatter.

Namespace

Drupal\options\Plugin\field\formatter
View source
class OptionsDefaultFormatter extends FormatterBase {

  /**
   * {@inheritdoc}
   */
  public function viewElements(EntityInterface $entity, $langcode, array $items) {
    $elements = array();
    $allowed_values = options_allowed_values($this->field, $this->instance, $entity);
    foreach ($items as $delta => $item) {
      if (isset($allowed_values[$item['value']])) {
        $output = field_filter_xss($allowed_values[$item['value']]);
      }
      else {

        // If no match was found in allowed values, fall back to the key.
        $output = field_filter_xss($item['value']);
      }
      $elements[$delta] = array(
        '#markup' => $output,
      );
    }
    return $elements;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormatterBase::$field protected property The field definition.
FormatterBase::$instance protected property The field instance definition.
FormatterBase::$label protected property The label display setting.
FormatterBase::$settings protected property The formatter settings. Overrides PluginSettingsBase::$settings
FormatterBase::$viewMode protected property The view mode.
FormatterBase::prepareView public function Allows formatters to load information for field values being displayed. Overrides FormatterInterface::prepareView 6
FormatterBase::settingsForm public function Returns a form to configure settings for the formatter. Overrides FormatterInterface::settingsForm 12
FormatterBase::settingsSummary public function Returns a short summary for the current formatter settings. Overrides FormatterInterface::settingsSummary 12
FormatterBase::view public function Builds a renderable array for one field on one entity instance. Overrides FormatterInterface::view
FormatterBase::__construct public function Constructs a FormatterBase object. Overrides PluginBase::__construct
OptionsDefaultFormatter::viewElements public function Builds a renderable array for a field value. Overrides FormatterInterface::viewElements
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginSettingsBase::$defaultSettingsMerged protected property Whether default settings have been merged into the current $settings.
PluginSettingsBase::getDefaultSettings public function Implements Drupal\field\Plugin\PluginSettingsInterface::getDefaultSettings(). Overrides PluginSettingsInterface::getDefaultSettings
PluginSettingsBase::getSetting public function Implements Drupal\field\Plugin\PluginSettingsInterface::getSetting(). Overrides PluginSettingsInterface::getSetting
PluginSettingsBase::getSettings public function Implements Drupal\field\Plugin\PluginSettingsInterface::getSettings(). Overrides PluginSettingsInterface::getSettings
PluginSettingsBase::mergeDefaults protected function Merges default settings values into $settings.
PluginSettingsBase::setSetting public function Implements Drupal\field\Plugin\PluginSettingsInterface::setSetting(). Overrides PluginSettingsInterface::setSetting
PluginSettingsBase::setSettings public function Implements Drupal\field\Plugin\PluginSettingsInterface::setSettings(). Overrides PluginSettingsInterface::setSettings