-
Notifications
You must be signed in to change notification settings - Fork 690
Expand file tree
/
Copy pathWidget.php
More file actions
101 lines (87 loc) · 2.07 KB
/
Widget.php
File metadata and controls
101 lines (87 loc) · 2.07 KB
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
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\base;
use Craft;
/**
* Widget is the base class for classes representing dashboard widgets in terms of objects.
*
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 3.0.0
*/
abstract class Widget extends SavableComponent implements WidgetInterface
{
use WidgetTrait;
/**
* @inheritdoc
*/
public static function isSelectable(): bool
{
return (static::allowMultipleInstances() || !Craft::$app->getDashboard()->doesUserHaveWidget(static::class));
}
/**
* Returns whether the widget can be selected more than once.
*
* @return bool Whether the widget can be selected more than once
*/
protected static function allowMultipleInstances(): bool
{
return true;
}
/**
* @inheritdoc
*/
public static function icon(): ?string
{
return null;
}
/**
* @inheritdoc
*/
public static function maxColspan(): ?int
{
return null;
}
/**
* @inheritdoc
*/
protected function defineRules(): array
{
$rules = parent::defineRules();
// Only validate the ID if it’s not a new widget
if (!$this->getIsNew()) {
$rules[] = [['id'], 'number', 'integerOnly' => true];
}
return $rules;
}
/**
* @inheritdoc
*/
public function getTitle(): ?string
{
// Default to the widget's display name
return static::displayName();
}
/**
* @inheritdoc
*/
public function getSubtitle(): ?string
{
return null;
}
/**
* @inheritdoc
*/
public function getBodyHtml(): ?string
{
$url = Craft::$app->getAssetManager()->getPublishedUrl('@app/web/assets/cp/dist', true, 'images/prg.jpg');
return <<<EOD
<div style="margin: 0 -24px -24px;">
<img style="display: block; width: 100%; border-radius: 0 0 4px 4px" src="$url">
</div>
EOD;
}
}