DefaultFileFormatter.php

Same filename and directory in other branches
  1. 9 core/modules/file/src/Plugin/Field/FieldFormatter/DefaultFileFormatter.php
  2. 8.9.x core/modules/file/src/Plugin/Field/FieldFormatter/DefaultFileFormatter.php
  3. 10 core/modules/file/src/Plugin/Field/FieldFormatter/DefaultFileFormatter.php

Namespace

Drupal\file\Plugin\Field\FieldFormatter

File

core/modules/file/src/Plugin/Field/FieldFormatter/DefaultFileFormatter.php

View source
<?php

namespace Drupal\file\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\Attribute\FieldFormatter;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Formatter for a text field on a file entity that links the field to the file.
 */
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;
    }

}

Classes

Title Deprecated Summary
DefaultFileFormatter Formatter for a text field on a file entity that links the field to the file.

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