You are here

protected function SvgResponsiveImageFormatter::fileGetContents in Svg Image 2.x

Same name and namespace in other branches
  1. 8 modules/svg_image_responsive/src/Plugin/Field/FieldFormatter/SvgResponsiveImageFormatter.php \Drupal\svg_image_responsive\Plugin\Field\FieldFormatter\SvgResponsiveImageFormatter::fileGetContents()
  2. 1.x modules/svg_image_responsive/src/Plugin/Field/FieldFormatter/SvgResponsiveImageFormatter.php \Drupal\svg_image_responsive\Plugin\Field\FieldFormatter\SvgResponsiveImageFormatter::fileGetContents()

Provides content of the file.

Parameters

\Drupal\file\Entity\File $file: File to handle.

Return value

string File content.

1 call to SvgResponsiveImageFormatter::fileGetContents()
SvgResponsiveImageFormatter::viewElements in modules/svg_image_responsive/src/Plugin/Field/FieldFormatter/SvgResponsiveImageFormatter.php
Builds a renderable array for a field value.

File

modules/svg_image_responsive/src/Plugin/Field/FieldFormatter/SvgResponsiveImageFormatter.php, line 247

Class

SvgResponsiveImageFormatter
Plugin implementation of the 'responsive_image' formatter.

Namespace

Drupal\svg_image_responsive\Plugin\Field\FieldFormatter

Code

protected function fileGetContents(File $file) {
  $fileUri = $file
    ->getFileUri();
  if (file_exists($fileUri)) {
    return file_get_contents($fileUri);
  }
  $this->logger
    ->error('File @file_uri (ID: @file_id) does not exists in filesystem.', [
    '@file_id' => $file
      ->id(),
    '@file_uri' => $fileUri,
  ]);
  return FALSE;
}