-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathUser.php
More file actions
84 lines (67 loc) · 2.08 KB
/
User.php
File metadata and controls
84 lines (67 loc) · 2.08 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
<?php
namespace presseddigital\linkit\models;
use Craft;
use craft\base\ElementInterface;
use craft\elements\User as CraftUser;
use presseddigital\linkit\base\ElementLink;
class User extends ElementLink
{
// Private
// =========================================================================
/**
* @var mixed|null
*/
private mixed $_user = null;
// Public
// =========================================================================
public ?string $userPath = null;
// Static
// =========================================================================
public static function elementType(): ?string
{
return CraftUser::class;
}
public static function settingsTemplatePath(): string
{
return 'linkit/types/settings/user';
}
public static function defaultUserPath(): string
{
return 'user/{id}';
}
// Public Methods
// =========================================================================
public function getUrl(): string
{
if ($this->getUser()) {
$userPath = static::defaultUserPath();
if ($this->userPath && $this->userPath != '') {
$userPath = $this->userPath;
}
return Craft::$app->getView()->renderObjectTemplate($userPath, $this->getUser());
}
return '';
}
public function getText(): string
{
return $this->getCustomOrDefaultText() ?? $this->getUser()->fullName ?? $this->getUser()->name ?? $this->getUrl() ?? '';
}
public function getUser(): ?ElementInterface
{
return $this->getElement();
// if (is_null($this->_user)) {
// $this->_user = Craft::$app->getUsers()->getUserById((int) $this->value, $this->owner->siteId ?? null);
// }
// return $this->_user;
}
/**
* @return mixed[]
*/
public function rules(): array
{
$rules = parent::rules();
$rules[] = ['userPath', 'string'];
return $rules;
}
}
class_alias(User::class, \fruitstudios\linkit\models\User::class);