| 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\Widget; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 Backend\View\Widget | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |  |