1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Modules\Html; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Contracts\BuilderContract; |
6
|
|
|
use GeminiLabs\SiteReviews\Modules\Sanitizer; |
7
|
|
|
use GeminiLabs\SiteReviews\Review; |
8
|
|
|
|
9
|
|
|
class MetaboxField extends Field |
10
|
|
|
{ |
11
|
|
|
public Review $review; |
12
|
|
|
|
13
|
|
|
public function __construct(array $args = []) |
14
|
|
|
{ |
15
|
|
|
$this->review = glsr_get_review(get_the_ID()); // review is cached |
16
|
|
|
parent::__construct($args); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function builder(): BuilderContract |
20
|
|
|
{ |
21
|
|
|
return glsr(MetaboxBuilder::class); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function buildField(): string |
25
|
|
|
{ |
26
|
|
|
return glsr(Template::class)->build('partials/editor/metabox-field', [ |
27
|
|
|
'context' => [ |
28
|
|
|
'class' => $this->classAttrField(), |
29
|
|
|
'field' => $this->buildFieldElement(), |
30
|
|
|
'label' => $this->buildFieldLabel(), |
31
|
|
|
], |
32
|
|
|
'field' => $this, |
33
|
|
|
'review' => $this->review, |
34
|
|
|
]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function buildFieldElement(): string |
38
|
|
|
{ |
39
|
|
|
return $this->fieldElement()->build([ |
40
|
|
|
'class' => 'glsr-input-value', |
41
|
|
|
'label' => '', // prevent the field label from being built |
42
|
|
|
]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function location(): string |
46
|
|
|
{ |
47
|
|
|
return 'metabox'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function classAttrField(): string |
51
|
|
|
{ |
52
|
|
|
$type = $this->isChoiceField() ? 'choice' : $this->original_type; |
53
|
|
|
return glsr(Sanitizer::class)->sanitizeAttrClass( |
54
|
|
|
"glsr-metabox-field glsr-field-{$type}" |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|