Passed
Push — develop ( ac6070...958965 )
by Andrew
04:55
created

OptimizedImages::getSettingsHtml()   C

Complexity

Conditions 11
Paths 163

Size

Total Lines 75
Code Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 51
c 0
b 0
f 0
dl 0
loc 75
rs 6.5024
cc 11
nc 163
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Image Optimize plugin for Craft CMS 3.x
4
 *
5
 * Automatically optimize images after they've been transformed
6
 *
7
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2017 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\imageoptimize\fields;
12
13
use craft\helpers\Html;
14
use nystudio107\imageoptimize\fields\OptimizedImages as OptimizedImagesField;
15
use nystudio107\imageoptimize\gql\types\generators\OptimizedImagesGenerator;
16
use nystudio107\imageoptimize\assetbundles\optimizedimagesfield\OptimizedImagesFieldAsset;
17
use nystudio107\imageoptimize\ImageOptimize;
18
use nystudio107\imageoptimize\models\OptimizedImage;
19
20
use Craft;
21
use craft\base\ElementInterface;
22
use craft\base\Field;
23
use craft\base\Volume;
24
use craft\elements\Asset;
25
use craft\fields\Matrix;
26
use craft\helpers\Json;
27
use craft\models\FieldLayout;
28
use craft\validators\ArrayValidator;
29
30
use yii\base\InvalidConfigException;
31
use yii\db\Exception;
32
use yii\db\Schema;
33
34
use verbb\supertable\fields\SuperTableField;
0 ignored issues
show
Bug introduced by
The type verbb\supertable\fields\SuperTableField was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
36
/** @noinspection MissingPropertyAnnotationsInspection */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
37
38
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
39
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
40
 * @package   ImageOptimize
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
41
 * @since     1.2.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
42
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
43
class OptimizedImages extends Field
44
{
45
    // Constants
46
    // =========================================================================
47
48
    const DEFAULT_ASPECT_RATIOS = [
49
        ['x' => 16, 'y' => 9],
50
    ];
51
    const DEFAULT_IMAGE_VARIANTS = [
52
        [
53
            'width'          => 1200,
54
            'useAspectRatio' => true,
55
            'aspectRatioX'   => 16.0,
56
            'aspectRatioY'   => 9.0,
57
            'retinaSizes'    => ['1'],
58
            'quality'        => 82,
59
            'format'         => 'jpg',
60
        ],
61
    ];
62
63
    // Public Properties
64
    // =========================================================================
65
66
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
67
     * @var array
68
     */
69
    public $fieldVolumeSettings = [];
70
71
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
72
     * @var array
73
     */
74
    public $ignoreFilesOfType = [];
75
76
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
77
     * @var bool
78
     */
79
    public $displayOptimizedImageVariants = true;
80
81
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
82
     * @var bool
83
     */
84
    public $displayDominantColorPalette = true;
85
86
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
87
     * @var bool
88
     */
89
    public $displayLazyLoadPlaceholderImages = true;
90
91
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
92
     * @var array
93
     */
94
    public $variants = [];
95
96
    // Private Properties
97
    // =========================================================================
98
99
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
100
     * @var array
101
     */
102
    private $aspectRatios = [];
0 ignored issues
show
Coding Style introduced by
Private member variable "aspectRatios" must be prefixed with an underscore
Loading history...
103
104
    // Static Methods
105
    // =========================================================================
106
107
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $config should have a doc-comment as per coding-style.
Loading history...
108
     * @inheritdoc
109
     */
110
    public function __construct(array $config = [])
111
    {
112
        // Unset any deprecated properties
113
        if (!empty($config)) {
114
            unset($config['transformMethod'], $config['imgixDomain']);
115
        }
116
        parent::__construct($config);
117
    }
118
119
    // Public Methods
120
    // =========================================================================
121
122
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
123
     * @inheritdoc
124
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
125
    public static function displayName(): string
126
    {
127
        return 'OptimizedImages';
128
    }
129
130
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
131
     * @inheritdoc
132
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
133
    public function init()
134
    {
135
        parent::init();
136
137
        // Handle cases where the plugin has been uninstalled
138
        if (ImageOptimize::$plugin !== null) {
139
            $settings = ImageOptimize::$plugin->getSettings();
140
            if ($settings) {
0 ignored issues
show
introduced by
$settings is of type nystudio107\imageoptimize\models\Settings, thus it always evaluated to true.
Loading history...
141
                if (empty($this->variants)) {
142
                    $this->variants = $settings->defaultVariants;
143
                }
144
                $this->aspectRatios = $settings->defaultAspectRatios;
145
            }
146
        }
147
        // If the user has deleted all default aspect ratios, provide a fallback
148
        if (empty($this->aspectRatios)) {
149
            $this->aspectRatios = self::DEFAULT_ASPECT_RATIOS;
150
        }
151
        // If the user has deleted all default variants, provide a fallback
152
        if (empty($this->variants)) {
153
            $this->variants = self::DEFAULT_IMAGE_VARIANTS;
154
        }
155
    }
156
157
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
158
     * @inheritdoc
159
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
160
    public function rules()
161
    {
162
        $rules = parent::rules();
163
        $rules = array_merge($rules, [
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
164
            [
165
                [
166
                    'displayOptimizedImageVariants',
167
                    'displayDominantColorPalette',
168
                    'displayLazyLoadPlaceholderImages',
169
                ],
170
                'boolean',
171
            ],
172
            [
173
                [
174
                    'ignoreFilesOfType',
175
                    'variants',
176
                ],
177
                ArrayValidator::class
178
            ],
179
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
180
181
        return $rules;
182
    }
183
184
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
185
     * @inheritdoc
186
     * @since 1.6.2
0 ignored issues
show
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 6 spaces but found 1
Loading history...
187
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
188
    public function getContentGqlType()
189
    {
190
        $typeArray = OptimizedImagesGenerator::generateTypes($this);
191
192
        return [
193
            'name' => $this->handle,
194
            'description' => 'Optimized Images field',
195
            'type' => array_shift($typeArray),
196
        ];
197
    }
198
199
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $asset should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $isNew should have a doc-comment as per coding-style.
Loading history...
200
     * @inheritdoc
201
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
202
    public function afterElementSave(ElementInterface $asset, bool $isNew)
203
    {
204
        parent::afterElementSave($asset, $isNew);
205
        // Update our OptimizedImages Field data now that the Asset has been saved
206
        if ($asset !== null && $asset instanceof Asset && $asset->id !== null) {
207
            // If this element is propagating, we don't need to redo the image saving for each site
208
            if (!$asset->propagating) {
209
                // If the scenario is Asset::SCENARIO_FILEOPS treat it as a new asset
210
                $scenario = $asset->getScenario();
211
                if ($isNew || $scenario === Asset::SCENARIO_FILEOPS ) {
212
                    /**
213
                     * If this is a newly uploaded/created Asset, we can save the variants
214
                     * via a queue job to prevent it from blocking
215
                     */
216
                    ImageOptimize::$plugin->optimizedImages->resaveAsset($asset->id);
217
                } else {
218
                    /**
219
                     * If it's not a newly uploaded/created Asset, they may have edited
220
                     * the image with the ImageEditor, so we need to update the variants
221
                     * immediately, so the AssetSelectorHud displays the new images
222
                     */
223
                    try {
224
                        ImageOptimize::$plugin->optimizedImages->updateOptimizedImageFieldData($this, $asset);
225
                    } catch (Exception $e) {
226
                        Craft::error($e->getMessage(), __METHOD__);
227
                    }
228
                }
229
            }
230
        }
231
    }
232
233
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $value should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $asset should have a doc-comment as per coding-style.
Loading history...
234
     * @inheritdoc
235
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
236
    public function normalizeValue($value, ElementInterface $asset = null)
237
    {
238
        // If we're passed in a string, assume it's JSON-encoded, and decode it
239
        if (\is_string($value) && !empty($value)) {
240
            $value = Json::decodeIfJson($value);
241
        }
242
        // If we're passed in an array, make a model from it
243
        if (\is_array($value)) {
244
            // Create a new OptimizedImage model and populate it
245
            $model = new OptimizedImage($value);
246
        } elseif ($value instanceof OptimizedImage) {
247
            $model = $value;
248
        } else {
249
            // Just create a new empty model
250
            $model = new OptimizedImage(null);
251
        }
252
253
        return $model;
254
    }
255
256
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
257
     * @inheritdoc
258
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
259
    public function getContentColumnType(): string
260
    {
261
        return Schema::TYPE_TEXT;
262
    }
263
264
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
265
     * @inheritdoc
266
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
267
    public function getSettingsHtml()
268
    {
269
        $namespace = Craft::$app->getView()->getNamespace();
270
        if (strpos($namespace, Matrix::class) !== false || strpos($namespace, SuperTableField::class) !== false) {
271
            // Render an error template, since the field only works when attached to an Asset
272
            try {
273
                return Craft::$app->getView()->renderTemplate(
274
                    'image-optimize/_components/fields/OptimizedImages_error',
275
                    [
276
                    ]
277
                );
278
            } catch (\Twig\Error\LoaderError $e) {
279
                Craft::error($e->getMessage(), __METHOD__);
280
            } catch (\yii\base\Exception $e) {
281
                Craft::error($e->getMessage(), __METHOD__);
282
            }
283
        }
284
285
        try {
286
            $reflect = new \ReflectionClass($this);
287
            $thisId = $reflect->getShortName();
288
        } catch (\ReflectionException $e) {
289
            Craft::error($e->getMessage(), __METHOD__);
290
            $thisId = 0;
291
        }
292
        // Get our id and namespace
293
        if (ImageOptimize::$craft35) {
294
            $id = Html::id($thisId);
0 ignored issues
show
Unused Code introduced by
The assignment to $id is dead and can be removed.
Loading history...
295
        } else {
296
            $id = Craft::$app->getView()->formatInputId($thisId);
297
        }
298
        $id = Craft::$app->getView()->formatInputId($thisId);
299
        $namespacedId = Craft::$app->getView()->namespaceInputId($id);
300
        $namespacePrefix = Craft::$app->getView()->namespaceInputName($thisId);
301
        Craft::$app->getView()->registerJs('new Craft.OptimizedImagesInput('.
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
302
            '"'.$namespacedId.'", '.
303
            '"'.$namespacePrefix.'"'.
304
            ');');
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 12.
Loading history...
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
305
306
        // Prep our aspect ratios
307
        $aspectRatios = [];
308
        $index = 1;
309
        foreach ($this->aspectRatios as $aspectRatio) {
310
            if ($index % 6 === 0) {
311
                $aspectRatio['break'] = true;
312
            }
313
            $aspectRatios[] = $aspectRatio;
314
            $index++;
315
        }
316
        $aspectRatio = ['x' => 2, 'y' => 2, 'custom' => true];
317
        $aspectRatios[] = $aspectRatio;
318
        // Get only the user-editable settings
319
        $settings = ImageOptimize::$plugin->getSettings();
320
321
        // Render the settings template
322
        try {
323
            return Craft::$app->getView()->renderTemplate(
324
                'image-optimize/_components/fields/OptimizedImages_settings',
325
                [
326
                    'field'        => $this,
327
                    'settings'     => $settings,
328
                    'aspectRatios' => $aspectRatios,
329
                    'id'           => $id,
330
                    'name'         => $this->handle,
331
                    'namespace'    => $namespacedId,
332
                    'fieldVolumes' => $this->getFieldVolumeInfo($this->handle),
333
                ]
334
            );
335
        } catch (\Twig\Error\LoaderError $e) {
336
            Craft::error($e->getMessage(), __METHOD__);
337
        } catch (\yii\base\Exception $e) {
338
            Craft::error($e->getMessage(), __METHOD__);
339
        }
340
341
        return '';
342
    }
343
344
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $value should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $element should have a doc-comment as per coding-style.
Loading history...
345
     * @inheritdoc
346
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
347
    public function getInputHtml($value, ElementInterface $element = null): string
348
    {
349
        if ($element !== null && $element instanceof Asset && $this->handle !== null) {
350
            /** @var Asset $element */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
351
            // Register our asset bundle
352
            try {
353
                Craft::$app->getView()->registerAssetBundle(OptimizedImagesFieldAsset::class);
354
            } catch (InvalidConfigException $e) {
355
                Craft::error($e->getMessage(), __METHOD__);
356
            }
357
358
            // Get our id and namespace
359
            if (ImageOptimize::$craft35) {
360
                $id = Html::id($this->handle);
361
            } else {
362
                $id = Craft::$app->getView()->formatInputId($this->handle);
363
            }
364
            $nameSpaceId = Craft::$app->getView()->namespaceInputId($id);
365
366
            // Variables to pass down to our field JavaScript to let it namespace properly
367
            $jsonVars = [
368
                'id'        => $id,
369
                'name'      => $this->handle,
370
                'namespace' => $nameSpaceId,
371
                'prefix'    => Craft::$app->getView()->namespaceInputId(''),
372
            ];
373
            $jsonVars = Json::encode($jsonVars);
374
            $view = Craft::$app->getView();
375
            $view->registerJs("$('#{$nameSpaceId}-field').ImageOptimizeOptimizedImages(".$jsonVars.");");
376
377
            $settings = ImageOptimize::$plugin->getSettings();
378
            $createVariants = ImageOptimize::$plugin->optimizedImages->shouldCreateVariants($this, $element);
379
            // Render the input template
380
            try {
381
                return Craft::$app->getView()->renderTemplate(
382
                    'image-optimize/_components/fields/OptimizedImages_input',
383
                    [
384
                        'name'           => $this->handle,
385
                        'value'          => $value,
386
                        'variants'       => $this->variants,
387
                        'field'          => $this,
388
                        'settings'       => $settings,
389
                        'elementId'      => $element->id,
390
                        'format'         => $element->getExtension(),
391
                        'id'             => $id,
392
                        'nameSpaceId'    => $nameSpaceId,
393
                        'createVariants' => $createVariants,
394
                    ]
395
                );
396
            } catch (\Twig\Error\LoaderError $e) {
397
                Craft::error($e->getMessage(), __METHOD__);
398
            } catch (\yii\base\Exception $e) {
399
                Craft::error($e->getMessage(), __METHOD__);
400
            }
401
        }
402
403
        // Render an error template, since the field only works when attached to an Asset
404
        try {
405
            return Craft::$app->getView()->renderTemplate(
406
                'image-optimize/_components/fields/OptimizedImages_error',
407
                [
408
                ]
409
            );
410
        } catch (\Twig\Error\LoaderError $e) {
411
            Craft::error($e->getMessage(), __METHOD__);
412
        } catch (\yii\base\Exception $e) {
413
            Craft::error($e->getMessage(), __METHOD__);
414
        }
415
416
        return '';
417
    }
418
419
    // Protected Methods
420
    // =========================================================================
421
422
    /**
423
     * Returns an array of asset volumes and their sub-folders
424
     *
425
     * @param string|null $fieldHandle
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
426
     *
427
     * @return array
428
     * @throws InvalidConfigException
429
     */
430
    protected function getFieldVolumeInfo($fieldHandle): array
431
    {
432
        $result = [];
433
        if ($fieldHandle !== null) {
434
            $volumes = Craft::$app->getVolumes()->getAllVolumes();
435
            $assets = Craft::$app->getAssets();
436
            foreach ($volumes as $volume) {
437
                if (is_subclass_of($volume, Volume::class)) {
438
                    /** @var Volume $volume */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
439
                    if ($this->volumeHasField($volume, $fieldHandle)) {
440
                        $tree = $assets->getFolderTreeByVolumeIds([$volume->id]);
441
                        $result[] = [
442
                            'name' => $volume->name,
443
                            'handle' => $volume->handle,
444
                            'subfolders' => $this->assembleSourceList($tree),
445
                        ];
446
                    }
447
                }
448
            }
449
        }
450
451
        return $result;
452
    }
453
454
    /**
455
     * See if the passed $volume has an OptimizedImagesField with the handle $fieldHandle
456
     *
457
     * @param Volume $volume
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
458
     *
459
     * @param string $fieldHandle
0 ignored issues
show
Coding Style introduced by
Parameter tags must be grouped together in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
460
     *
461
     * @return bool
462
     * @throws InvalidConfigException
463
     */
464
    protected function volumeHasField(Volume $volume, string $fieldHandle): bool
465
    {
466
        $result = false;
467
        /** @var FieldLayout $fieldLayout */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
468
        $fieldLayout = $volume->getFieldLayout();
469
        // Loop through the fields in the layout to see if there is an OptimizedImages field
470
        if ($fieldLayout) {
0 ignored issues
show
introduced by
$fieldLayout is of type craft\models\FieldLayout, thus it always evaluated to true.
Loading history...
471
            $fields = $fieldLayout->getFields();
472
            foreach ($fields as $field) {
473
                if ($field instanceof OptimizedImagesField && $field->handle === $fieldHandle) {
474
                    $result = true;
475
                }
476
            }
477
        }
478
479
        return $result;
480
    }
481
482
    /**
483
     * Transforms an asset folder tree into a source list.
484
     *
485
     * @param array $folders
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
486
     * @param bool  $includeNestedFolders
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
487
     *
488
     * @return array
489
     */
490
    protected function assembleSourceList(array $folders, bool $includeNestedFolders = true): array
491
    {
492
        $sources = [];
493
494
        foreach ($folders as $folder) {
495
            $children = $folder->getChildren();
496
            foreach ($children as $child) {
497
                $sources[$child->uid] = $child->name;
498
            }
499
        }
500
501
        return $sources;
502
    }
503
}
504