public function render(array $data, \Cake\View\Form\ContextInterface $context) {

        $data += [
            '_input'  => [],
            '_button' => [],
            'id' => $data['name'],
            'count-label' => __('files selected'),
            'button-label' => (isset($data['multiple']) && $data['multiple']) ? __('Choose Files') : __('Choose File'),
            'templateVars' => []
        ];

        $fakeInputCustomOptions = $data['_input'];
        $fakeButtonCustomOptions = $data['_button'];
        $countLabel = $data['count-label'];
        $buttonLabel = $data['button-label'];
        unset($data['_input'], $data['_button'],
            $data['type'], $data['count-label'],
            $data['button-label']);
        // avoid javascript errors due to invisible control
        unset($data['required']);

        $fileInput = $this->_file->render($data + [
            'style' => 'display: none;',
            'onchange' => "document.getElementById('".$data['id']."-input').value = " .
                "(this.files.length <= 1) ? " .
                "(this.files.length ? this.files[0].name : '') " .
                ": this.files.length + ' ' + '" . $countLabel . "';",
            'escape' => false
        ], $context);

        if (!empty($data['val']) && is_array($data['val'])) {
            if (isset($data['val']['name']) || count($data['val']) == 1) {
                $fakeInputCustomOptions += [
                    'value' => (isset($data['val']['name'])) ? $data['val']['name'] : $data['val'][0]['name']
                ];
            }
            else {
                $fakeInputCustomOptions += [
                    'value' => count($data['val']) . ' ' . $countLabel
                ];
            }
        }

        $fakeInput = $this->_input->render($fakeInputCustomOptions + [
            'name' => $this->_fakeFieldName($data['name']),
            'readonly' => 'readonly',
            'id' => $data['id'].'-input',
            'onclick' => "document.getElementById('".$data['id']."').click();",
            'escape' => false
        ], $context);

        $fakeButton = $this->_button->render($fakeButtonCustomOptions + [
            'type' => 'button',
            'text' => $buttonLabel,
            'onclick' => "document.getElementById('".$data['id']."').click();"
        ], $context);

        return $this->_templates->format('fancyFileInput', [
            'fileInput' => $fileInput,
            'button' => $fakeButton,
            'input' => $fakeInput,
            'attrs' => $this->_templates->formatAttributes($data),
            'templateVars' => $data['templateVars']
        ]);
    }