You are here

public function PublicFileSchemeHandler::addAttributes in Acquia Content Hub 8.2

Throws

\Exception

Overrides FileSchemeHandlerInterface::addAttributes

File

src/Plugin/FileSchemeHandler/PublicFileSchemeHandler.php, line 82

Class

PublicFileSchemeHandler
The handler for files with a public file scheme.

Namespace

Drupal\acquia_contenthub\Plugin\FileSchemeHandler

Code

public function addAttributes(CDFObject $object, FileInterface $file) {
  $uri = $file
    ->getFileUri();
  $directory_path = $this->streamWrapperManager
    ->getViaUri($uri)
    ->getDirectoryPath();
  if (version_compare(\Drupal::VERSION, '8.8.0', '>=')) {
    $url = Url::fromUri('base:' . $directory_path . '/' . StreamWrapperManager::getTarget($uri), [
      'absolute' => TRUE,
    ])
      ->toString();
  }
  else {
    $url = Url::fromUri('base:' . $directory_path . '/' . file_uri_target($uri), [
      'absolute' => TRUE,
    ])
      ->toString();
  }
  $object
    ->addAttribute('file_scheme', CDFAttribute::TYPE_STRING, 'public');
  $object
    ->addAttribute('file_location', CDFAttribute::TYPE_STRING, $url);
  $object
    ->addAttribute('file_uri', CDFAttribute::TYPE_STRING, $uri);
}