UrlPlainFormatter.php in Drupal 8        
                          
                  
                        
  
  
  
  
File
  core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php
  
    View source  
  <?php
namespace Drupal\file\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\file\FileInterface;
class UrlPlainFormatter extends FileFormatterBase {
  
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];
    foreach ($this
      ->getEntitiesToView($items, $langcode) as $delta => $file) {
      assert($file instanceof FileInterface);
      $elements[$delta] = [
        '#markup' => $file
          ->createFileUrl(),
        '#cache' => [
          'tags' => $file
            ->getCacheTags(),
        ],
      ];
    }
    return $elements;
  }
}