Loading src/Plugin/Field/FieldFormatter/ZipFileBase.php +29 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,9 @@ namespace Drupal\field_zip_file\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FormatterBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\File\FileUrlGeneratorInterface; use Drupal\field_zip_file\Plugin\Field\FieldType\ZipFileItem; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Formatter that shows the file size in a human readable way. Loading @@ -20,6 +22,32 @@ use Drupal\field_zip_file\Plugin\Field\FieldType\ZipFileItem; */ class ZipFileBase extends FormatterBase { /** * File url generator object. * * @var \Drupal\Core\File\FileUrlGeneratorInterface */ protected $fileUrlGenerator; /** * Constructs new ZipFileBase object. * * @param \Drupal\Core\File\FileUrlGeneratorInterface $fileUrlGenerator * File url generator object. */ public function __construct(FileUrlGeneratorInterface $fileUrlGenerator) { $this->fileUrlGenerator = $fileUrlGenerator; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('file_url_generator') ); } /** * {@inheritdoc} */ Loading Loading @@ -64,7 +92,7 @@ class ZipFileBase extends FormatterBase { $url = NULL; if ($file = $zip_file->get('entity')->getValue()) { if ($file_info = _field_zip_file($file)) { $url = \Drupal::service('file_url_generator')->generateAbsoluteString($file_info['folder_uri']); $url = $this->fileUrlGenerator->generateAbsoluteString($file_info['folder_uri']); } } if ($this->getSetting('default_index')) { Loading Loading
src/Plugin/Field/FieldFormatter/ZipFileBase.php +29 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,9 @@ namespace Drupal\field_zip_file\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FormatterBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\File\FileUrlGeneratorInterface; use Drupal\field_zip_file\Plugin\Field\FieldType\ZipFileItem; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Formatter that shows the file size in a human readable way. Loading @@ -20,6 +22,32 @@ use Drupal\field_zip_file\Plugin\Field\FieldType\ZipFileItem; */ class ZipFileBase extends FormatterBase { /** * File url generator object. * * @var \Drupal\Core\File\FileUrlGeneratorInterface */ protected $fileUrlGenerator; /** * Constructs new ZipFileBase object. * * @param \Drupal\Core\File\FileUrlGeneratorInterface $fileUrlGenerator * File url generator object. */ public function __construct(FileUrlGeneratorInterface $fileUrlGenerator) { $this->fileUrlGenerator = $fileUrlGenerator; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('file_url_generator') ); } /** * {@inheritdoc} */ Loading Loading @@ -64,7 +92,7 @@ class ZipFileBase extends FormatterBase { $url = NULL; if ($file = $zip_file->get('entity')->getValue()) { if ($file_info = _field_zip_file($file)) { $url = \Drupal::service('file_url_generator')->generateAbsoluteString($file_info['folder_uri']); $url = $this->fileUrlGenerator->generateAbsoluteString($file_info['folder_uri']); } } if ($this->getSetting('default_index')) { Loading