1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Form
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * Form Field class for the Joomla Platform.
14 * Provides an input field for files
15 *
16 * @link http://www.w3.org/TR/html-markup/input.file.html#input.file
17 * @since 11.1
18 */
19 class JFormFieldFile extends JFormField
20 {
21 /**
22 * The form field type.
23 *
24 * @var string
25 * @since 11.1
26 */
27 protected $type = 'File';
28
29 /**
30 * The accepted file type list.
31 *
32 * @var mixed
33 * @since 3.2
34 */
35 protected $accept;
36
37 /**
38 * Name of the layout being used to render the field
39 *
40 * @var string
41 * @since 3.6
42 */
43 protected $layout = 'joomla.form.field.file';
44
45 /**
46 * Method to get certain otherwise inaccessible properties from the form field object.
47 *
48 * @param string $name The property name for which to the the value.
49 *
50 * @return mixed The property value or null.
51 *
52 * @since 3.2
53 */
54 public function __get($name)
55 {
56 switch ($name)
57 {
58 case 'accept':
59 return $this->accept;
60 }
61
62 return parent::__get($name);
63 }
64
65 /**
66 * Method to set certain otherwise inaccessible properties of the form field object.
67 *
68 * @param string $name The property name for which to the the value.
69 * @param mixed $value The value of the property.
70 *
71 * @return void
72 *
73 * @since 3.2
74 */
75 public function __set($name, $value)
76 {
77 switch ($name)
78 {
79 case 'accept':
80 $this->accept = (string) $value;
81 break;
82
83 default:
84 parent::__set($name, $value);
85 }
86 }
87
88 /**
89 * Method to attach a JForm object to the field.
90 *
91 * @param SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
92 * @param mixed $value The form field value to validate.
93 * @param string $group The field name group control value. This acts as an array container for the field.
94 * For example if the field has name="foo" and the group value is set to "bar" then the
95 * full field name would end up being "bar[foo]".
96 *
97 * @return boolean True on success.
98 *
99 * @see JFormField::setup()
100 * @since 3.2
101 */
102 public function setup(SimpleXMLElement $element, $value, $group = null)
103 {
104 $return = parent::setup($element, $value, $group);
105
106 if ($return)
107 {
108 $this->accept = (string) $this->element['accept'];
109 }
110
111 return $return;
112 }
113
114 /**
115 * Method to get the field input markup for the file field.
116 * Field attributes allow specification of a maximum file size and a string
117 * of accepted file extensions.
118 *
119 * @return string The field input markup.
120 *
121 * @note The field does not include an upload mechanism.
122 * @see JFormFieldMedia
123 * @since 11.1
124 */
125 protected function getInput()
126 {
127 return $this->getRenderer($this->layout)->render($this->getLayoutData());
128 }
129
130 /**
131 * Method to get the data to be passed to the layout for rendering.
132 *
133 * @return array
134 *
135 * @since 3.6
136 */
137 protected function getLayoutData()
138 {
139 $data = parent::getLayoutData();
140
141 $extraData = array(
142 'accept' => $this->accept,
143 'multiple' => $this->multiple,
144 );
145
146 return array_merge($data, $extraData);
147 }
148 }
149