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