1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace flipbox\saml\core\fields; |
8
|
|
|
|
9
|
|
|
use craft\base\ElementInterface; |
10
|
|
|
use craft\base\Field; |
11
|
|
|
use craft\elements\User; |
12
|
|
|
use flipbox\saml\core\records\ProviderIdentityInterface; |
13
|
|
|
use flipbox\saml\core\traits\EnsureSamlPlugin; |
14
|
|
|
use yii\db\Query; |
15
|
|
|
|
16
|
|
|
abstract class AbstractExternalIdentity extends Field |
17
|
|
|
{ |
18
|
|
|
use EnsureSamlPlugin; |
19
|
|
|
|
20
|
|
|
public static function displayName(): string |
21
|
|
|
{ |
22
|
|
|
return 'External Identity'; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @inheritdoc |
27
|
|
|
*/ |
28
|
|
|
public static function hasContentColumn(): bool |
29
|
|
|
{ |
30
|
|
|
return false; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function normalizeValue($value, ElementInterface $element = null) |
34
|
|
|
{ |
35
|
|
|
if (! ($element instanceof User)) { |
36
|
|
|
return null; |
37
|
|
|
} |
38
|
|
|
/** @var User $element */ |
39
|
|
|
return $this->getSamlPlugin()->getProviderIdentity()->findByUser($element); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getInputHtml($value, ElementInterface $element = null): string |
43
|
|
|
{ |
44
|
|
|
return $this->getStaticHtml($value, $element); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param $value |
49
|
|
|
* @param ElementInterface $element |
50
|
|
|
* @return string |
51
|
|
|
* @throws \Twig_Error_Loader |
52
|
|
|
* @throws \yii\base\Exception |
53
|
|
|
*/ |
54
|
|
|
public function getStaticHtml($value, ElementInterface $element): string |
55
|
|
|
{ |
56
|
|
|
if (! ($value instanceof Query)) { |
57
|
|
|
return ''; |
58
|
|
|
} |
59
|
|
|
return \Craft::$app->getView()->renderTemplate( |
60
|
|
|
'saml-core/_cp/fields/external-id', |
61
|
|
|
[ |
62
|
|
|
'identities' => $value, |
63
|
|
|
'element' => $element, |
64
|
|
|
] |
65
|
|
|
); |
66
|
|
|
// return " |
67
|
|
|
//<div class='meta'> |
68
|
|
|
// NameID: {$value->nameId} |
69
|
|
|
// <br/> |
70
|
|
|
// Issuer: {$value->provider->getEntityId()} |
71
|
|
|
// <br/> |
72
|
|
|
// Last Login: {$value->lastLoginDate} |
73
|
|
|
//</div > |
74
|
|
|
//"; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):