1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CakeCMS Backend |
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 Backend |
10
|
|
|
* @license MIT |
11
|
|
|
* @copyright MIT License http://www.opensource.org/licenses/mit-license.php |
12
|
|
|
* @link https://github.com/CakeCMS/Backend". |
13
|
|
|
* @author Sergey Kalistratov <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Backend\View\Helper; |
17
|
|
|
|
18
|
|
|
use JBZoo\Utils\Arr; |
19
|
|
|
use Cake\Core\Exception\Exception; |
20
|
|
|
use Backend\View\Helper\Traits\PrepareHelpers; |
21
|
|
|
use Core\View\Helper\FormHelper as CoreFormHelper; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class FormHelper |
25
|
|
|
* |
26
|
|
|
* @package Backend\View\Helper |
27
|
|
|
*/ |
28
|
|
|
class FormHelper extends CoreFormHelper |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
use PrepareHelpers; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* List of helpers used by this helper. |
35
|
|
|
* |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
public $helpers = [ |
39
|
|
|
'Url' => ['className' => 'Core.Url'], |
40
|
|
|
'Html' => ['className' => 'Backend.Html'] |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Creates file input widget. |
45
|
|
|
* |
46
|
|
|
* @param string $fieldName Name of a field, in the form "modelname.fieldname" |
47
|
|
|
* @param array $options Array of HTML attributes. |
48
|
|
|
* |
49
|
|
|
* @return string A generated file input. |
50
|
|
|
*/ |
51
|
|
|
public function file($fieldName, array $options = []) |
52
|
|
|
{ |
53
|
|
|
$content = parent::file($fieldName, $options); |
54
|
|
|
$options = $this->_parseOptions($fieldName, $options); |
55
|
|
|
|
56
|
|
|
$options['type'] = __FUNCTION__; |
57
|
|
|
|
58
|
|
|
$result = $this->_inputContainerTemplate([ |
59
|
|
|
'error' => null, |
60
|
|
|
'errorSuffix' => null, |
61
|
|
|
'content' => $content, |
62
|
|
|
'options' => $options |
63
|
|
|
]); |
64
|
|
|
|
65
|
|
|
return $result; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Constructor hook method. |
70
|
|
|
* |
71
|
|
|
* @param array $config |
72
|
|
|
* @throws Exception |
73
|
|
|
*/ |
74
|
|
|
public function initialize(array $config) |
75
|
|
|
{ |
76
|
|
|
$this->_configWrite('prepareBtnClass', function (FormHelper $form, $options, $button) { |
77
|
|
|
return $this->_prepareBtn($form, $options, $button); |
78
|
|
|
}); |
79
|
|
|
|
80
|
|
|
$this->_configWrite('templates', 'Backend.templates/form'); |
81
|
|
|
|
82
|
|
|
parent::initialize($config); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Form switcher. |
87
|
|
|
* |
88
|
|
|
* @param string $fieldName |
89
|
|
|
* @param array $options |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function switcher($fieldName, array $options = []) |
93
|
|
|
{ |
94
|
|
|
$input = parent::checkbox($fieldName, $options); |
|
|
|
|
95
|
|
|
|
96
|
|
|
$options += [ |
97
|
|
|
'before' => __d('backend', 'Off'), |
98
|
|
|
'after' => __d('backend', 'On') |
99
|
|
|
]; |
100
|
|
|
|
101
|
|
|
$title = (Arr::key('title', $options)) ? $options['title'] : $fieldName; |
102
|
|
|
|
103
|
|
|
if (!empty($title)) { |
104
|
|
|
$title = $this->Html->div('switch-title', $title); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$content = $this->formatTemplate(__FUNCTION__, [ |
108
|
|
|
'input' => $input, |
109
|
|
|
'title' => $title, |
110
|
|
|
'after' => $options['after'], |
111
|
|
|
'before' => $options['before'], |
112
|
|
|
'lever' => '<span class="lever"></span>' |
113
|
|
|
]); |
114
|
|
|
|
115
|
|
|
return $content; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.