class DefaultFileFormatter

Same name and namespace in other branches
  1. 10 core/modules/file/src/Plugin/Field/FieldFormatter/DefaultFileFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\DefaultFileFormatter
  2. 11.x core/modules/file/src/Plugin/Field/FieldFormatter/DefaultFileFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\DefaultFileFormatter
  3. 8.9.x core/modules/file/src/Plugin/Field/FieldFormatter/DefaultFileFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\DefaultFileFormatter

Formatter for a text field on a file entity that links the field to the file.

Plugin annotation


@FieldFormatter(
  id = "file_link",
  label = @Translation("File link"),
  field_types = {
    "string"
  }
)

Hierarchy

Expanded class hierarchy of DefaultFileFormatter

File

core/modules/file/src/Plugin/Field/FieldFormatter/DefaultFileFormatter.php, line 19

Namespace

Drupal\file\Plugin\Field\FieldFormatter
View source
class DefaultFileFormatter extends BaseFieldFileFormatterBase {
  
  /**
   * {@inheritdoc}
   */
  public static function defaultSettings() {
    $settings = parent::defaultSettings();
    $settings['link_to_file'] = TRUE;
    return $settings;
  }
  
  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    // We don't call the parent in order to bypass the link to file form.
    return $form;
  }
  
  /**
   * {@inheritdoc}
   */
  protected function viewValue(FieldItemInterface $item) {
    return $item->value;
  }

}

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