Completed
Pull Request — master (#588)
by
unknown
14:32
created

File::defaultRender()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
namespace Xoops\Form;
13
14
/**
15
 * File - a file upload field
16
 *
17
 * @category  Xoops\Form\File
18
 * @package   Xoops\Form
19
 * @author    Kazumi Ono <[email protected]>
20
 * @copyright 2001-2015 XOOPS Project (http://xoops.org)
21
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22
 * @link      http://xoops.org
23
 */
24
class File extends Element
25
{
26
    /**
27
     * Constructor
28
     *
29
     * @param string|array $caption Caption or array of all attributes
30
     * @param string       $name    name attribute
31
     */
32 3
    public function __construct($caption, $name = null)
33
    {
34 3
        if (is_array($caption)) {
35 1
            parent::__construct($caption);
36
        } else {
37 3
            parent::__construct();
38 3
            $this->setCaption($caption);
39 3
            $this->set('name', $name);
40
        }
41 3
        $this->set('type', 'file');
42 3
    }
43
44
    /**
45
     * defaultRender
46
     *
47
     * @return string rendered form element
48
     */
49 2
    public function defaultRender()
50
    {
51 2
        $attributes = $this->renderAttributeString();
52
53 2
        return '<input ' . $attributes . ' ' . $this->getExtra() . ' />'
54 2
            . '<input type="hidden" name="xoops_upload_file[]" id="xoops_upload_file[]" value="'
55 2
            . $this->getName() . '">';
56
    }
57
}
58