drupal 9 custom local stream wrapper

Solutions on MaxInterview for drupal 9 custom local stream wrapper by the best coders in the world

showing results for - "drupal 9 custom local stream wrapper"
Tom
28 Sep 2018
1This is a modified snippet from a live real estate project to define a custom stream wrapper.
2
3Add the stream wrapper as a service in your services YML file:
4
5    stream_wrapper.pics:
6      class: Drupal\mymod\PicsStreamWrapper
7      tags:
8        - { name: stream, scheme: pics }
9
10
11
12Create the stream wrapper class extending LocalStream:
13
14    <?php
15
16    namespace Drupal\mymod;
17
18    use Drupal\Core\StreamWrapper\LocalStream;
19
20    class PicsStreamWrapper extends LocalStream {
21
22        public function getDirectoryPath() {
23            return 'sites/default/files/pics';
24        }
25
26        public function getExternalUrl() {
27            global $base_url;
28
29            $path = str_replace('\\', '/', $this->getTarget());
30
31            return $base_url . '/' . self::getDirectoryPath() . '/' . $path;
32        }
33
34        public function getName() {
35            return 'Pics Stream';
36        }
37
38        public function getDescription() {
39            return 'Pics stream for listing property pics.';
40        }
41    }
42
43
44