WingsuitStreamWrapper.php in Gin Layout Builder 8.2
File
src/StreamWrapper/WingsuitStreamWrapper.php
View source
<?php
namespace Drupal\wingsuit_companion\StreamWrapper;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\StreamWrapper\LocalReadOnlyStream;
use Drupal\system_stream_wrapper\StreamWrapper\ExtensionStreamBase;
class WingsuitStreamWrapper extends LocalReadOnlyStream {
protected $themeHandler;
public function __construct(ConfigFactory $config_factory = NULL) {
if ($config_factory === NULL) {
$config_factory = \Drupal::configFactory();
}
$this->config = $config_factory
->get('wingsuit_companion.config');
}
public function getDirectoryPath() {
$dist_path = $this->config
->get('dist_path');
return $dist_path;
}
public function getName() {
return $this
->t('Wingsuit files');
}
public function getDescription() {
return $this
->t('Local files stored under wingsuit dist directory.');
}
public function getExternalUrl() {
$dir = $this
->getDirectoryPath();
if (empty($dir)) {
throw new \InvalidArgumentException("Extension directory for {$this->uri} does not exist.");
}
$path = rtrim(base_path() . $dir . '/' . $this
->getTarget(), '/');
return $this
->getRequest()
->getUriForPath($path);
}
protected function getRequest() {
if (!isset($this->request)) {
$this->request = \Drupal::service('request_stack')
->getCurrentRequest();
}
return $this->request;
}
}