|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace mmikkel\cacheflag\utilities; |
|
4
|
|
|
|
|
5
|
|
|
use Craft; |
|
6
|
|
|
use craft\base\Utility; |
|
7
|
|
|
|
|
8
|
|
|
use mmikkel\cacheflag\CacheFlag; |
|
9
|
|
|
|
|
10
|
|
|
class CacheFlagUtility extends Utility |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
/** @inheritdoc */ |
|
14
|
|
|
public static function id(): string |
|
15
|
|
|
{ |
|
16
|
|
|
return 'cache-flag-utility'; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** @inheritdoc */ |
|
20
|
|
|
public static function displayName(): string |
|
21
|
|
|
{ |
|
22
|
|
|
return 'Cache Flag'; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** @inheritdoc */ |
|
26
|
|
|
public static function icon(): ?string |
|
27
|
|
|
{ |
|
28
|
|
|
return 'flag'; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return string |
|
33
|
|
|
* @throws \Twig\Error\LoaderError |
|
34
|
|
|
* @throws \Twig\Error\RuntimeError |
|
35
|
|
|
* @throws \Twig\Error\SyntaxError |
|
36
|
|
|
* @throws \yii\base\Exception |
|
37
|
|
|
*/ |
|
38
|
|
|
public static function contentHtml(): string |
|
39
|
|
|
{ |
|
40
|
|
|
$sources = [ |
|
41
|
|
|
'sections' => [ |
|
42
|
|
|
'column' => 'sectionId', |
|
43
|
|
|
'name' => Craft::t('app', 'Sections'), |
|
44
|
|
|
'sources' => Craft::$app->getEntries()->getAllSections(), |
|
45
|
|
|
], |
|
46
|
|
|
'categoryGroups' => [ |
|
47
|
|
|
'column' => 'categoryGroupId', |
|
48
|
|
|
'name' => Craft::t('app', 'Category Groups'), |
|
49
|
|
|
'sources' => Craft::$app->getCategories()->getAllGroups(), |
|
50
|
|
|
], |
|
51
|
|
|
'volumes' => [ |
|
52
|
|
|
'column' => 'volumeId', |
|
53
|
|
|
'name' => Craft::t('app', 'Asset Volumes'), |
|
54
|
|
|
'sources' => Craft::$app->getVolumes()->getAllVolumes(), |
|
55
|
|
|
], |
|
56
|
|
|
'globalSets' => [ |
|
57
|
|
|
'column' => 'globalSetId', |
|
58
|
|
|
'name' => Craft::t('app', 'Global Sets'), |
|
59
|
|
|
'sources' => Craft::$app->getGlobals()->getAllSets(), |
|
60
|
|
|
], |
|
61
|
|
|
'elementTypes' => [ |
|
62
|
|
|
'column' => 'elementType', |
|
63
|
|
|
'name' => Craft::t('app', 'Element Types'), |
|
64
|
|
|
'sources' => array_map(function (string $elementType) { |
|
65
|
|
|
return [ |
|
66
|
|
|
'id' => $elementType, |
|
67
|
|
|
'name' => $elementType, |
|
68
|
|
|
]; |
|
69
|
|
|
}, Craft::$app->getElements()->getAllElementTypes()), |
|
70
|
|
|
], |
|
71
|
|
|
]; |
|
72
|
|
|
|
|
73
|
|
|
if (Craft::$app->getEdition() === 1) { |
|
74
|
|
|
$sources['userGroups'] = [ |
|
75
|
|
|
'column' => 'userGroupId', |
|
76
|
|
|
'name' => Craft::t('app', 'User Groups'), |
|
77
|
|
|
'sources' => Craft::$app->getUserGroups()->getAllGroups(), |
|
78
|
|
|
]; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return Craft::$app->getView()->renderTemplate('cache-flag/_utility.twig', [ |
|
82
|
|
|
'sources' => $sources, |
|
83
|
|
|
'allFlags' => CacheFlag::getInstance()->cacheFlag->getAllFlags(), |
|
84
|
|
|
'version' => Craft::$app->getPlugins()->getPlugin('cache-flag')->getVersion(), |
|
85
|
|
|
'documentationUrl' => Craft::$app->getPlugins()->getComposerPluginInfo('cache-flag')['documentationUrl'] ?? null, |
|
86
|
|
|
]); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|