-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathLibraryStream.php
More file actions
73 lines (61 loc) · 2.07 KB
/
Copy pathLibraryStream.php
File metadata and controls
73 lines (61 loc) · 2.07 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace Drupal\patternkit\StreamWrapper;
use Drupal\Core\Asset\AttachedAssets;
use Drupal\Core\StreamWrapper\PublicStream;
/**
* Defines a Drupal library (library://) stream wrapper class.
*
* Provides support for retrieving library files.
*/
class LibraryStream extends PublicStream {
/**
* Override to interpret the uri as the actual library file.
*
* {@inheritdoc}
*/
protected function getTarget($uri = NULL) {
if (!isset($uri)) {
$uri = $this->uri;
}
[, $path] = explode('://', $uri, 2);
// Remove erroneous leading or trailing, forward-slashes and backslashes.
$uri = trim($path, '\/');
/** @var \Drupal\Core\Asset\AssetResolverInterface $asset_resolver */
$asset_resolver = \Drupal::service('asset.resolver');
[$extension, $library, $type_level] = explode('/', $uri);
// @todo Allow retrieving specific filenames and css levels.
$filename = substr($uri, strlen($extension . $library . $type_level));
[$type, $level] = array_pad(explode('.', $type_level), 2, NULL);
// Resolve the attached libraries into asset collections.
$assets = new AttachedAssets();
$assets->setLibraries(["$extension/$library"]);
switch ($type) {
case 'js':
$js_header_footer = $asset_resolver->getJsAssets($assets, TRUE);
$query_assets = array_merge($js_header_footer[0], $js_header_footer[1]);
break;
case 'css':
$query_assets = $asset_resolver->getCssAssets($assets, TRUE);
break;
default:
$js = $asset_resolver->getJsAssets($assets, TRUE);
$css = $asset_resolver->getCssAssets($assets, TRUE);
// @todo Create a temporary {libraryname}.json that holds the data.
return ['js' => $js, 'css' => $css];
}
[, $target] = explode('://', reset($query_assets)['data'], 2);
return $target;
}
/**
* {@inheritdoc}
*/
public function getName() {
return t('Library files');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return t('Library files for usage in processing and rendering.');
}
}