|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CakeCMS Core |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the of the simple cms based on CakePHP 3. |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @package Core |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
* @copyright MIT License http://www.opensource.org/licenses/mit-license.php |
|
12
|
|
|
* @link https://github.com/CakeCMS/Core". |
|
13
|
|
|
* @author Sergey Kalistratov <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Core\View\Helper; |
|
17
|
|
|
|
|
18
|
|
|
use Cake\View\View; |
|
19
|
|
|
use Cake\Utility\Hash; |
|
20
|
|
|
use Cake\Core\Configure; |
|
21
|
|
|
use Core\View\Helper\Traits\HelperTrait; |
|
22
|
|
|
use Cake\View\Helper\FormHelper as CakeFormHelper; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class FormHelper |
|
26
|
|
|
* |
|
27
|
|
|
* @package Core\View\Helper |
|
28
|
|
|
* @property \Core\View\Helper\UrlHelper $Url |
|
29
|
|
|
* @property \Core\View\Helper\HtmlHelper $Html |
|
30
|
|
|
*/ |
|
31
|
|
|
class FormHelper extends CakeFormHelper |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
use HelperTrait; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* List of helpers used by this helper. |
|
38
|
|
|
* |
|
39
|
|
|
* @var array |
|
40
|
|
|
*/ |
|
41
|
|
|
public $helpers = [ |
|
42
|
|
|
'Url' => ['className' => 'Core.Url'], |
|
43
|
|
|
'Html' => ['className' => 'Core.Html'], |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Hold js form type. |
|
48
|
|
|
* |
|
49
|
|
|
* @var bool |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $_isJsForm = false; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* HtmlHelper constructor. |
|
55
|
|
|
* |
|
56
|
|
|
* @param View $View |
|
57
|
|
|
* @param array $config |
|
58
|
|
|
*/ |
|
59
|
|
|
public function __construct(View $View, array $config = []) |
|
60
|
|
|
{ |
|
61
|
|
|
parent::__construct($View, $config); |
|
62
|
|
|
$this->_configWrite('btnPref', Configure::read('Cms.btnPref')); |
|
63
|
|
|
$this->_configWrite('iconPref', Configure::read('Cms.iconPref')); |
|
64
|
|
|
$this->_configWrite('classPrefix', Configure::read('Cms.classPrefix')); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Creates a `<button>` tag. |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $title |
|
71
|
|
|
* @param array $options |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
public function button($title, array $options = []) |
|
75
|
|
|
{ |
|
76
|
|
|
$options = $this->addClass($options, $this->_class(__FUNCTION__)); |
|
77
|
|
|
$options = $this->_getBtnClass($options); |
|
78
|
|
|
|
|
79
|
|
|
list($title, $options) = $this->_createIcon($this->Html, $title, $options); |
|
80
|
|
|
|
|
81
|
|
|
return parent::button($title, $options); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Create html form. |
|
86
|
|
|
* |
|
87
|
|
|
* @param mixed $model |
|
88
|
|
|
* @param array $options |
|
89
|
|
|
* @return string |
|
90
|
|
|
*/ |
|
91
|
|
|
public function create($model = null, array $options = []) |
|
92
|
|
|
{ |
|
93
|
|
|
$options += ['process' => false, 'jsForm' => false]; |
|
94
|
|
|
$options = $this->addClass($options, $this->_class('form')); |
|
95
|
|
|
|
|
96
|
|
|
$isProcess = $options['process']; |
|
97
|
|
|
|
|
98
|
|
|
if ($isProcess != false) { |
|
99
|
|
|
$_options = [ |
|
100
|
|
|
'url' => [ |
|
101
|
|
|
'plugin' => $this->request->param('plugin'), |
|
102
|
|
|
'controller' => $this->request->param('controller'), |
|
103
|
|
|
'action' => 'process' |
|
104
|
|
|
] |
|
105
|
|
|
]; |
|
106
|
|
|
|
|
107
|
|
|
$options['jsForm'] = true; |
|
108
|
|
|
$options = Hash::merge($_options, $options); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
$isJsForm = $options['jsForm']; |
|
112
|
|
|
if ($isJsForm) { |
|
113
|
|
|
$this->_isJsForm = true; |
|
114
|
|
|
$options = $this->addClass($options, 'jsForm'); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
unset($options['process']); |
|
118
|
|
|
unset($options['jsForm']); |
|
119
|
|
|
|
|
120
|
|
|
return parent::create($model, $options); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* End html form. |
|
125
|
|
|
* |
|
126
|
|
|
* @param array $secureAttributes |
|
127
|
|
|
* @return string |
|
128
|
|
|
*/ |
|
129
|
|
|
public function end(array $secureAttributes = []) |
|
130
|
|
|
{ |
|
131
|
|
|
if ($this->_isJsForm) { |
|
132
|
|
|
return implode('', [ |
|
133
|
|
|
$this->hidden('action', ['value' => '', 'class' => 'jsFormAction']), |
|
134
|
|
|
parent::end($secureAttributes) |
|
135
|
|
|
]); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
return parent::end($secureAttributes); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|