TextInputControl.php
1.67 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
<?php
namespace YahnisElsts\AdminMenuEditor\Customizable\Controls;
use YahnisElsts\AdminMenuEditor\Customizable\Rendering\Renderer;
use YahnisElsts\AdminMenuEditor\Customizable\Settings\StringSetting;
class TextInputControl extends ClassicControl {
protected $type = 'text';
protected $koComponentName = 'ame-text-input';
/**
* @var StringSetting
*/
protected $mainSetting;
/**
* @var bool Whether to style the value as code (e.g. using fixed width fonts).
*/
protected $isCode = false;
protected $inputType = 'text';
public function __construct($settings = array(), $params = array()) {
parent::__construct($settings, $params);
$this->hasPrimaryInput = true;
$this->isCode = !empty($params['isCode']);
if ( !empty($params['inputType']) ) {
$this->inputType = $params['inputType'];
}
}
public function renderContent(Renderer $renderer) {
$classes = array('regular-text');
if ( $this->isCode ) {
$classes[] = 'code';
}
$classes[] = 'ame-text-input-control';
$value = $this->getMainSettingValue();
//phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- buildInputElement() is safe
echo $this->buildInputElement(
array(
'type' => $this->inputType,
'value' => ($value === null) ? '' : $value,
'class' => $classes,
'style' => $this->styles,
'data-bind' => $this->makeKoDataBind([
'value' => $this->getKoObservableExpression($value),
]),
)
);
//phpcs:enable
$this->outputSiblingDescription();
}
protected function getKoComponentParams() {
$params = parent::getKoComponentParams();
$params['isCode'] = $this->isCode;
$params['inputType'] = $this->inputType;
return $params;
}
}