Completed
Push — master ( 633f87...d85777 )
by Cheren
03:16
created

FileWidget   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 40
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 19 2
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\Widget\MaterializeCss;
17
18
use Cake\View\Form\ContextInterface;
19
use Cake\View\Widget\FileWidget as CakeFileWidget;
20
use JBZoo\Utils\Arr;
21
22
/**
23
 * Class FileWidget
24
 *
25
 * @package Core\View\Widget\MaterializeCss
26
 */
27
class FileWidget extends CakeFileWidget
28
{
29
30
    /**
31
     * Render a file upload form widget.
32
     *
33
     * Data supports the following keys:
34
     *
35
     * - `name` - Set the input name.
36
     * - `escape` - Set to false to disable HTML escaping.
37
     *
38
     * All other keys will be converted into HTML attributes.
39
     * Unlike other input objects the `val` property will be specifically
40
     * ignored.
41
     *
42
     * @param   array $data The data to build a file input with.
43
     * @param   \Cake\View\Form\ContextInterface $context The current form context.
44
     *
45
     * @return  string HTML elements.
46
     */
47
    public function render(array $data, ContextInterface $context)
48
    {
49
        $data += [
50
            'name'         => '',
51
            'templateVars' => [],
52
            'escape'       => true
53
        ];
54
55
        unset($data['val']);
56
57
        $title = (Arr::key('title', $data)) ? $data['title'] : $data['name'];
58
59
        return $this->_templates->format('file', [
60
            'title'        => $title,
61
            'name'         => $data['name'],
62
            'templateVars' => $data['templateVars'],
63
            'attrs'        => $this->_templates->formatAttributes($data, ['name'])
64
        ]);
65
    }
66
}
67