Skip to content

Commit 0f00a74

Browse files
torenwarepaul-m
authored andcommitted
Issue #2638290 by Torenware, Mile23, jkopel: Create stream_wrapper_example
1 parent b8ba3fd commit 0f00a74

17 files changed

+1782
-5
lines changed

examples.module

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function examples_toolbar() {
5454
'phpunit_example' => 'phpunit_example_description',
5555
'plugin_type_example' => 'plugin_type_example.description',
5656
'simpletest_example' => 'simpletest_example_description',
57+
'stream_wrapper_example' => 'stream_wrapper_example.description',
5758
'queue_example' => 'queue_example',
5859
'tablesort_example' => 'tablesort_example_description',
5960
'tour_example' => 'tour_example_description',

file_example/file_example.info.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ core: 8.x
66
dependencies:
77
- examples
88
- file
9+
- stream_wrapper_example

file_example/src/Form/FileExampleReadWriteForm.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ protected function getDefaultFile() {
140140
* @return Drupal\stream_wrapper_example\StreamWrapper\SessionWrapper|bool
141141
* Wrapper object to manipulate the SESSION storage or FALSE if the session
142142
* wrapper is unavailable.
143-
*
144-
* @todo Update this to be meaningful when stream_wrapper_example is
145-
* completed. https://www.drupal.org/node/2638290
146143
*/
147144
protected function getSessionWrapper() {
145+
if ($this->sessionSchemeEnabled) {
146+
return new \Drupal\stream_wrapper_example\StreamWrapper\SessionWrapper($this->requestStack);
147+
}
148148
return FALSE;
149149
}
150150

file_example/src/Tests/FileExampleTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ public function testFileExampleBasic() {
5454
'Unmanaged using PHP',
5555
);
5656
foreach ($buttons as $button) {
57-
// For each scheme supported by Drupal + the session:// wrapper.
58-
$schemes = array('public', 'private', 'temporary');
57+
// For each scheme supported by Drupal + the session:// wrapper,
58+
// which is defined in the stream_wrapper_exampnle.
59+
$schemes = array('public', 'private', 'temporary', 'session');
5960
foreach ($schemes as $scheme) {
6061
// Create a directory for use.
6162
$dirname = $scheme . '://' . $this->randomMachineName(10);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Drupal\stream_wrapper_example\Controller;
4+
5+
use Drupal\Core\Controller\ControllerBase;
6+
7+
/**
8+
* Controller class for the Stream Wrapper Example.
9+
*/
10+
class StreamWrapperExampleController extends ControllerBase {
11+
12+
/**
13+
* Description page for the example.
14+
*/
15+
public function description() {
16+
$build = [
17+
'description' => [
18+
'#theme' => 'example_description',
19+
],
20+
];
21+
return $build;
22+
}
23+
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Drupal\stream_wrapper_example\PathProcessor;
4+
5+
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
6+
use Symfony\Component\HttpFoundation\Request;
7+
8+
/**
9+
* Defines a path processor to rewrite file URLs.
10+
*
11+
* As the route system does not allow arbitrary amount of parameters convert
12+
* the file path to a query parameter on the request. This is similar to what
13+
* Core does for the system/files/* URLs.
14+
*/
15+
class PathProcessorSessions implements InboundPathProcessorInterface {
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public function processInbound($path, Request $request) {
21+
if (strpos($path, '/examples/stream_wrapper_example/files/') === 0 && !$request->query->has('file')) {
22+
$file_path = preg_replace('|^\/examples\/stream_wrapper_example\/files\/|', '', $path);
23+
$request->query->set('file', $file_path);
24+
// We return the route we want to match.
25+
return '/examples/stream_wrapper_example/files';
26+
}
27+
return $path;
28+
}
29+
30+
}

0 commit comments

Comments
 (0)