FileDownloadLinkFormatter.php in Commerce File 8.2        
                          
                  
                        
  
  
  
  
  
File
  src/Plugin/Field/FieldFormatter/FileDownloadLinkFormatter.php
  
    View source  
  <?php
namespace Drupal\commerce_file\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\file\Plugin\Field\FieldFormatter\DescriptionAwareFileFormatterBase;
class FileDownloadLinkFormatter extends DescriptionAwareFileFormatterBase {
  
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];
    
    foreach ($this
      ->getEntitiesToView($items, $langcode) as $delta => $file) {
      $item = $file->_referringItem;
      $elements[$delta] = [
        '#theme' => 'commerce_file_download_link',
        '#file' => $file,
        '#description' => $this
          ->getSetting('use_description_as_link_text') ? $item->description : NULL,
        '#cache' => [
          'tags' => $file
            ->getCacheTags(),
        ],
      ];
      
      if (isset($item->_attributes)) {
        $elements[$delta] += [
          '#attributes' => [],
        ];
        $elements[$delta]['#attributes'] += $item->_attributes;
        
        unset($item->_attributes);
      }
    }
    return $elements;
  }
}