-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathStyleGuideStream.php
More file actions
56 lines (46 loc) · 1.39 KB
/
StyleGuideStream.php
File metadata and controls
56 lines (46 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
namespace Drupal\server_style_guide\StreamWrapper;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\StreamWrapper\LocalReadOnlyStream;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Defines the server-style-guide:// stream wrapper.
*
* Provides read-only access to images bundled within the server_style_guide
* module, allowing Drupal image styles to process them without requiring files
* to be in public:// or private://.
*/
class StyleGuideStream extends LocalReadOnlyStream {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function getName() {
return $this->t('Style guide module files');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->t('Read-only image files bundled with the server_style_guide module.');
}
/**
* {@inheritdoc}
*/
public function getDirectoryPath(): string {
// Two levels up from src/StreamWrapper/ lands at the module root.
return dirname(__DIR__, 2) . '/images';
}
/**
* {@inheritdoc}
*/
public function getExternalUrl(): string {
global $base_url;
$path = str_replace('\\', '/', $this->getTarget());
$path = UrlHelper::encodePath($path);
$module_dir = dirname(__DIR__, 2);
$relative_path = substr($module_dir, strlen(DRUPAL_ROOT) + 1);
return "{$base_url}/{$relative_path}/images/{$path}";
}
}