-
Notifications
You must be signed in to change notification settings - Fork 451
/
OptionSelectInstance.php
91 lines (74 loc) · 2 KB
/
OptionSelectInstance.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
<?php
namespace Concrete\Core\Attribute\Component;
use Concrete\Core\Attribute\View;
use Concrete\Core\Entity\Attribute\Key\Key;
use Concrete\Core\Entity\Attribute\Value\Value\SelectValueOption;
class OptionSelectInstance
{
/**
* @var string
*/
protected $accessToken;
/**
* @var Key
*/
protected $attributeKey;
/**
* @return mixed
*/
public function getAccessToken()
{
return $this->accessToken;
}
/**
* @param mixed $accessToken
*/
public function setAccessToken($accessToken): void
{
$this->accessToken = $accessToken;
}
/**
* @return Key
*/
public function getAttributeKey(): Key
{
return $this->attributeKey;
}
/**
* @param Key $attributeKey
*/
public function setAttributeKey(Key $attributeKey): void
{
$this->attributeKey = $attributeKey;
}
/**
* Returns the URL needed to search these options using the autocomplete component
*
* @return string
*/
public function getDataSourceUrl(): string
{
$view = new View($this->getAttributeKey());
return $view->action('load_autocomplete_values');
}
/**
* Returns the URL needed to selected options when coming to a pre-filled option component
*
* @return string
*/
public function getSelectedOptionsUrl(): string
{
$view = new View($this->getAttributeKey());
return $view->action('select_autocomplete_values');
}
public function createResultFromOption(SelectValueOption $option): array
{
// We prefix these with SelectAttributeOption: because that's how we can differentiate
// in the request between items that already exist in the db and new items.
$data = [
'id' => 'SelectAttributeOption:' . $option->getSelectAttributeOptionID(),
'primary_label' => $option->getSelectAttributeOptionDisplayValue('text'),
];
return $data;
}
}