Skip to content
Snippets Groups Projects
Commit 9d09a8d2 authored by Chris Leppanen's avatar Chris Leppanen Committed by Chris Leppanen
Browse files

Issue #2728865 by twistor: Allow custom names for stream wrappers

parent 4cafd9aa
Branches
Tags 8.x-1.0-alpha4
No related merge requests found
......@@ -73,6 +73,9 @@ $schemes = [
// Optional settings that apply to all adapters.
'name' => 'Custom stream wrapper name', // Defaults to Flysystem: scheme.
'description' => 'Custom description', // Defaults to Flysystem: scheme.
'cache' => TRUE, // Cache filesystem metadata. Not necessary for
// the local driver.
......
......@@ -25,14 +25,22 @@ class FlysystemBridge extends FlysystemStreamWrapper implements StreamWrapperInt
* {@inheritdoc}
*/
public function getName() {
return $this->t('Flysystem: @scheme', ['@scheme' => $this->getProtocol()]);
$scheme = $this->getProtocol();
$name = (string) $this->getFactory()->getSettings($scheme)['name'];
$default = $this->t('Flysystem: @scheme', ['@scheme' => $scheme]);
return $name !== '' ? $this->t($name) : $default;
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->t('Flysystem: @scheme', ['@scheme' => $this->getProtocol()]);
$scheme = $this->getProtocol();
$description = (string) $this->getFactory()->getSettings($scheme)['description'];
$default = $this->t('Flysystem: @scheme', ['@scheme' => $scheme]);
return $description !== '' ? $this->t($description) : $default;
}
/**
......
......@@ -29,6 +29,8 @@ class FlysystemFactory {
'config' => [],
'replicate' => FALSE,
'cache' => FALSE,
'name' => '',
'description' => '',
];
/**
......@@ -148,6 +150,19 @@ class FlysystemFactory {
return array_keys($this->settings);
}
/**
* Finds the settings for a given scheme.
*
* @param string $scheme
* The scheme.
*
* @return array
* The settings array from settings.php.
*/
public function getSettings($scheme) {
return isset($this->settings[$scheme]) ? $this->settings[$scheme] : $this->defaults;
}
/**
* Calls FlysystemPluginInterface::ensure() on each plugin.
*
......@@ -199,17 +214,4 @@ class FlysystemFactory {
return $adapter;
}
/**
* Finds the settings for a given scheme.
*
* @param string $scheme
* The scheme.
*
* @return array
* The settings array from settings.php.
*/
protected function getSettings($scheme) {
return isset($this->settings[$scheme]) ? $this->settings[$scheme] : $this->defaults;
}
}
......@@ -43,6 +43,8 @@ class FlysystemBridgeTest extends UnitTestCase {
$factory->getFilesystem('testscheme')->willReturn($this->filesystem);
$factory->getSettings('testscheme')->willReturn(['name' => '', 'description' => '']);
$container = new ContainerBuilder();
$container->set('flysystem_factory', $factory->reveal());
\Drupal::setContainer($container);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment