You are here

trait FileLinkFormatterTrait in File Link 8

Same name and namespace in other branches
  1. 2.0.x src/FileLinkFormatterTrait.php \Drupal\file_link\FileLinkFormatterTrait

Provide common methods for file link formatters.

Hierarchy

2 files declare their use of FileLinkFormatterTrait
FileLinkFormatter.php in src/Plugin/Field/FieldFormatter/FileLinkFormatter.php
FileLinkSeparateFormatter.php in src/Plugin/Field/FieldFormatter/FileLinkSeparateFormatter.php

File

src/FileLinkFormatterTrait.php, line 10

Namespace

Drupal\file_link
View source
trait FileLinkFormatterTrait {

  /**
   * {@inheritdoc}
   */
  public static function defaultSettings() {
    return [
      'format_size' => TRUE,
    ] + parent::defaultSettings();
  }

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $elements = parent::settingsForm($form, $form_state);
    $elements['format_size'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Format size value'),
      '#default_value' => $this
        ->getSetting('format_size'),
    ];
    return $elements;
  }

  /**
   * {@inheritdoc}
   */
  public function settingsSummary() {
    $summary = parent::settingsSummary();
    $summary[] = $this
      ->getSetting('format_size') ? $this
      ->t('Size value: formatted') : $this
      ->t('Size value: plain');
    return $summary;
  }

}

Members