$this->t('Display the file download URI'), '#type' => 'checkbox', '#default_value' => $this->getSetting('file_download_path'), ]; return $form; } /** * {@inheritdoc} */ protected function viewValue(FieldItemInterface $item) { $value = $item->value; if ($this->getSetting('file_download_path')) { // @todo Wrap in file_url_transform_relative(). This is currently // impossible. See BaseFieldFileFormatterBase::viewElements(). Fix in // https://www.drupal.org/node/2646744. $value = file_create_url($value); } return $value; } /** * {@inheritdoc} */ public static function isApplicable(FieldDefinitionInterface $field_definition) { return parent::isApplicable($field_definition) && $field_definition->getName() === 'uri'; } }