Skip to content

Commit e234155

Browse files
committed
add getLabelValue
1 parent 1832e64 commit e234155

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/Base/Type.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public function getPublicValue()
3636
return $this->getValue();
3737
}
3838

39+
public function getLabelValue()
40+
{
41+
return $this->getPublicValue();
42+
}
43+
3944
public function getAdminJson()
4045
{
4146
return $this->getValue();

src/Types/MultiSelectType.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public function getValue()
2929
return [];
3030
}
3131

32+
if(is_array($this->value)){
33+
return $this->value;
34+
}
35+
3236
return explode(',', $this->value);
3337
}
3438

@@ -50,6 +54,24 @@ public function getPublicValue()
5054
return $this->getValue();
5155
}
5256

57+
public function getLabelValue(){
58+
$value = $this->getValue();
59+
60+
$result = [];
61+
foreach($value as $valueItem){
62+
$found = null;
63+
foreach($this->options as $option){
64+
if($option['value'] === $valueItem){
65+
$found = $option['label'];
66+
}
67+
}
68+
69+
$result[] = $found ?? $valueItem;
70+
}
71+
72+
return implode(', ', $result);
73+
}
74+
5375
public function getDatabaseValue()
5476
{
5577
if (!$this->value) {

src/Types/SelectType.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function setOptions(array $options)
1414
{
1515
$this->options = $options;
1616
}
17-
17+
1818
public function getType()
1919
{
2020
return FieldType::Select;
@@ -43,6 +43,18 @@ public function getPublicValue()
4343
return $this->getValue();
4444
}
4545

46+
public function getLabelValue(){
47+
$valueItem = $this->getValue();
48+
49+
foreach($this->options as $option){
50+
if($option['value'] === $valueItem){
51+
return $option['label'];
52+
}
53+
}
54+
55+
return $valueItem;
56+
}
57+
4658
public function getAdminJson()
4759
{
4860
return $this->getValue();

0 commit comments

Comments
 (0)