-
Notifications
You must be signed in to change notification settings - Fork 611
/
AssetIndexes.php
109 lines (96 loc) · 2.76 KB
/
AssetIndexes.php
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\utilities;
use Craft;
use craft\base\Utility;
use craft\events\ListVolumesEvent;
use craft\helpers\App;
use craft\helpers\Html;
use craft\i18n\Locale;
use craft\models\Volume;
use craft\web\assets\assetindexes\AssetIndexesAsset;
use yii\base\Event;
/**
* AssetIndexes represents a AssetIndexes dashboard widget.
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 3.0.0
*/
class AssetIndexes extends Utility
{
/**
* @event ListVolumesEvent The event that is triggered when listing the available volumes to index.
* @since 4.4.0
*/
public const EVENT_LIST_VOLUMES = 'listVolumes';
/**
* @inheritdoc
*/
public static function displayName(): string
{
return Craft::t('app', 'Asset Indexes');
}
/**
* @inheritdoc
*/
public static function id(): string
{
return 'asset-indexes';
}
/**
* @inheritdoc
*/
public static function icon(): ?string
{
return 'image';
}
/**
* Returns all of the available volumes for indexing.
*
* @return Volume[]
* @since 4.4.6
*/
public static function volumes(): array
{
// Fire a 'listVolumes' event
$event = new ListVolumesEvent([
'volumes' => Craft::$app->getVolumes()->getAllVolumes(),
]);
Event::trigger(self::class, self::EVENT_LIST_VOLUMES, $event);
return $event->volumes;
}
/**
* @inheritdoc
*/
public static function contentHtml(): string
{
$volumeOptions = [];
foreach (static::volumes() as $volume) {
$volumeOptions[] = [
'label' => Html::encode($volume->name),
'value' => $volume->id,
];
}
$view = Craft::$app->getView();
$checkboxSelectHtml = $view->renderTemplate('_includes/forms/checkboxSelect.twig', [
'class' => 'first',
'name' => 'volumes',
'options' => $volumeOptions,
'showAllOption' => true,
'values' => '*',
]);
$view->registerAssetBundle(AssetIndexesAsset::class);
$dateFormat = Craft::$app->getLocale()->getDateTimeFormat('short', Locale::FORMAT_PHP);
$existingIndexingSessions = Craft::$app->getAssetIndexer()->getExistingIndexingSessions();
return $view->renderTemplate('_components/utilities/AssetIndexes.twig', [
'existingSessions' => $existingIndexingSessions,
'checkboxSelectHtml' => $checkboxSelectHtml,
'dateFormat' => $dateFormat,
'isEphemeral' => App::isEphemeral(),
]);
}
}