a8a44fe324ac4960b94e208aaf470a465e42c119
[yaffs-website] / web / core / modules / file / src / Plugin / Field / FieldFormatter / DefaultFileFormatter.php
1 <?php
2
3 namespace Drupal\file\Plugin\Field\FieldFormatter;
4
5 use Drupal\Core\Field\FieldItemInterface;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Formatter for a text field on a file entity that links the field to the file.
10  *
11  * @FieldFormatter(
12  *   id = "file_link",
13  *   label = @Translation("File link"),
14  *   field_types = {
15  *     "string"
16  *   }
17  * )
18  */
19 class DefaultFileFormatter extends BaseFieldFileFormatterBase {
20
21   /**
22    * {@inheritdoc}
23    */
24   public static function defaultSettings() {
25     $settings = parent::defaultSettings();
26     $settings['link_to_file'] = TRUE;
27
28     return $settings;
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function settingsForm(array $form, FormStateInterface $form_state) {
35     // We don't call the parent in order to bypass the link to file form.
36     return $form;
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   protected function viewValue(FieldItemInterface $item) {
43     return $item->value;
44   }
45
46 }