Skip to content

Commit 5f30cc5

Browse files
committed
Replace deprecated code and update constructor calls.
1 parent 418a695 commit 5f30cc5

6 files changed

Lines changed: 32 additions & 20 deletions

‎patternkit.services.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ services:
1111
arguments: ['@cache.discovery', '@config.factory', '@plugin.manager.library.pattern', '@lock', '@module_handler', '@app.root', '@theme.manager']
1212
patternkit.asset.library.parser.file:
1313
class: Drupal\patternkit\Asset\PatternLibraryParser\FilePatternLibraryParser
14-
arguments: ['@serialization.json', '@app.root', '@module_handler', '@theme.manager']
14+
arguments: ['@serialization.json', '@app.root', '@module_handler', '@theme.manager', '@stream_wrapper_manager']
1515
patternkit.asset.library.parser.json:
1616
class: Drupal\patternkit\Asset\PatternLibraryParser\JSONPatternLibraryParser
17-
arguments: ['@serialization.json', '@app.root', '@module_handler', '@theme.manager']
17+
arguments: ['@serialization.json', '@app.root', '@module_handler', '@theme.manager', '@stream_wrapper_manager']
1818
patternkit.asset.library.parser.twig:
1919
class: Drupal\patternkit\Asset\PatternLibraryParser\TwigPatternLibraryParser
20-
arguments: ['@serialization.json', '@app.root', '@module_handler', '@theme.manager']
20+
arguments: ['@serialization.json', '@app.root', '@module_handler', '@theme.manager', '@stream_wrapper_manager']
2121
plugin.manager.library.pattern:
2222
class: Drupal\patternkit\PatternLibraryPluginManager
2323
arguments: ['@container.namespaces', '@cache.discovery', '@module_handler', '@theme_handler']

‎src/Asset/PatternLibraryParser/FilePatternLibraryParser.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Drupal\Component\Serialization\SerializationInterface;
66
use Drupal\Core\Asset\Exception\InvalidLibraryFileException;
77
use Drupal\Core\Extension\ModuleHandlerInterface;
8+
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
89
use Drupal\Core\Theme\ThemeManagerInterface;
910
use Drupal\patternkit\Entity\PatternInterface;
1011
use Drupal\patternkit\PatternEditorConfig;
@@ -29,15 +30,18 @@ class FilePatternLibraryParser extends PatternLibraryParserBase {
2930
* Allows modules to alter library parsing.
3031
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
3132
* Allows themes to alter library parsing.
33+
* @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper
34+
* The stream wrapper manager.
3235
*/
3336
public function __construct(
3437
SerializationInterface $serializer,
3538
$root,
3639
ModuleHandlerInterface $module_handler,
37-
ThemeManagerInterface $theme_manager) {
40+
ThemeManagerInterface $theme_manager,
41+
StreamWrapperManagerInterface $stream_wrapper) {
3842

3943
$this->serializer = $serializer;
40-
parent::__construct($root, $module_handler, $theme_manager);
44+
parent::__construct($root, $module_handler, $theme_manager, $stream_wrapper);
4145
}
4246

4347
/**

‎src/Asset/PatternLibraryParser/JSONPatternLibraryParser.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Drupal\patternkit\PatternLibrary;
1010
use Drupal\patternkit\PatternLibraryJSONParserTrait;
1111
use Drupal\patternkit\Asset\PatternLibraryParserBase;
12+
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
1213

1314
/**
1415
* Parses a Twig pattern library collection into usable metadata.
@@ -27,15 +28,18 @@ class JSONPatternLibraryParser extends PatternLibraryParserBase {
2728
* Allows modules to alter library parsing.
2829
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
2930
* Allows themes to alter library parsing.
31+
* @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper
32+
* The stream wrapper manager.
3033
*/
3134
public function __construct(
3235
SerializationInterface $serializer,
3336
$root,
3437
ModuleHandlerInterface $module_handler,
35-
ThemeManagerInterface $theme_manager) {
38+
ThemeManagerInterface $theme_manager,
39+
StreamWrapperManagerInterface $stream_wrapper) {
3640

3741
$this->serializer = $serializer;
38-
parent::__construct($root, $module_handler, $theme_manager);
42+
parent::__construct($root, $module_handler, $theme_manager, $stream_wrapper);
3943
}
4044

4145
/**

‎src/Asset/PatternLibraryParser/TwigPatternLibraryParser.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Drupal\patternkit\PatternLibrary;
1313
use Drupal\patternkit\PatternLibraryJSONParserTrait;
1414
use Drupal\patternkit\Asset\PatternLibraryParserBase;
15+
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
1516

1617
/**
1718
* Parses a Twig pattern library collection into usable metadata.
@@ -30,15 +31,18 @@ class TwigPatternLibraryParser extends PatternLibraryParserBase {
3031
* Allows modules to alter library parsing.
3132
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
3233
* Allows themes to alter library parsing.
34+
* @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper
35+
* The stream wrapper manager.
3336
*/
3437
public function __construct(
3538
SerializationInterface $serializer,
3639
$root,
3740
ModuleHandlerInterface $module_handler,
38-
ThemeManagerInterface $theme_manager) {
41+
ThemeManagerInterface $theme_manager,
42+
StreamWrapperManagerInterface $stream_wrapper) {
3943

4044
$this->serializer = $serializer;
41-
parent::__construct($root, $module_handler, $theme_manager);
45+
parent::__construct($root, $module_handler, $theme_manager, $stream_wrapper);
4246
}
4347

4448
/**

‎src/Asset/PatternLibraryParser/WebcomponentPatternLibraryParser.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Drupal\patternkit\Asset\PatternLibraryParser;
44

5-
use Drupal\Core\File\FileSystem;
5+
use Drupal\Core\File\FileSystemInterface;
66
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
77
use Drupal\patternkit\Asset\PatternLibraryParserBase;
88
use Drupal\patternkit\Entity\Pattern;
@@ -51,7 +51,7 @@ public static function fetchAssets($subtype, $config): PatternInterface {
5151
);
5252

5353
$dir = "public://patternkit/$subtype/{$config->instance_id}";
54-
if (!\Drupal::service('file_system')->prepareDirectory($dir, FileSystem::CREATE_DIRECTORY)) {
54+
if (!\Drupal::service('file_system')->prepareDirectory($dir, FileSystemInterface::CREATE_DIRECTORY)) {
5555
\Drupal::service('messenger')->addMessage(
5656
t(
5757
'Unable to create folder or save metadata/assets for plugin @plugin',
@@ -66,7 +66,7 @@ public static function fetchAssets($subtype, $config): PatternInterface {
6666
$save_result = \Drupal::service('file_system')->saveData(
6767
$request->getBody()->getContents(),
6868
"$dir/body.html",
69-
FileSystem::EXISTS_REPLACE
69+
FileSystemInterface::EXISTS_REPLACE
7070
);
7171

7272
// Convert stream wrapper to relative path, if appropriate.

‎src/Asset/PatternLibraryParserBase.php‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public static function fetchAssets($subtype, $config): PatternInterface {
122122
$save_result = \Drupal::service('file_system')->saveData(
123123
$pk_obj->body,
124124
"$dir/manifest.json",
125-
FileSystem::EXISTS_REPLACE
125+
FileSystemInterface::EXISTS_REPLACE
126126
);
127127
$pk_obj->body = $save_result;
128128

@@ -258,10 +258,10 @@ public static function fetchSingleAsset($dir, $asset_prefix, $asset_url) {
258258
// $dest_path = "$dir/" . md5($asset_src->data) . ".$asset_type";.
259259
$dest_path = $path . $filename;
260260

261-
$save_result = file_unmanaged_save_data(
261+
$save_result = \Drupal::service('file_system')->saveData(
262262
$asset_src->data,
263263
$dest_path,
264-
FILE_EXISTS_REPLACE
264+
FileSystemInterface::EXISTS_REPLACE
265265
);
266266

267267
if ($save_result == FALSE) {
@@ -270,10 +270,10 @@ public static function fetchSingleAsset($dir, $asset_prefix, $asset_url) {
270270
}
271271

272272
// Convert stream wrapper to relative path, if appropriate.
273-
$scheme = file_uri_scheme($save_result);
274-
if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
275-
$wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
276-
$save_result = $wrapper->getDirectoryPath() . "/" . file_uri_target(
273+
$scheme = StreamWrapperManagerInterface::getScheme($save_result);
274+
if ($scheme && \Drupal::service('stream_wrapper_manager')->isValidScheme($scheme)) {
275+
$wrapper = \Drupal::service('stream_wrapper_manager')->getViaScheme($scheme);
276+
$save_result = $wrapper->getDirectoryPath() . "/" . \Drupal::service('stream_wrapper_manager')::getTarget(
277277
$save_result
278278
);
279279
}
@@ -324,7 +324,7 @@ public function fetchFragmentAssets($subtype, $config, &$pk_obj): PatternInterfa
324324
$save_result = \Drupal::service('file_system')->saveData(
325325
$result->data,
326326
"$dir/body.html",
327-
FileSystem::EXISTS_REPLACE
327+
FileSystemInterface::EXISTS_REPLACE
328328
);
329329

330330
// Convert stream wrapper to relative path, if appropriate.

0 commit comments

Comments
 (0)