Path: blob/master/src/view/form/control/PHUIFormFileControl.php
13400 views
<?php12final class PHUIFormFileControl3extends AphrontFormControl {45private $allowMultiple;67protected function getCustomControlClass() {8return 'phui-form-file-upload';9}1011public function setAllowMultiple($allow_multiple) {12$this->allowMultiple = $allow_multiple;13return $this;14}1516public function getAllowMultiple() {17return $this->allowMultiple;18}1920protected function renderInput() {21$file_id = $this->getID();2223Javelin::initBehavior(24'phui-file-upload',25array(26'fileInputID' => $file_id,27'inputName' => $this->getName(),28'uploadURI' => '/file/dropupload/',29'chunkThreshold' => PhabricatorFileStorageEngine::getChunkThreshold(),30));313233// If the control has a value, add a hidden input which submits it as a34// default. This allows the file control to mean "don't change anything",35// instead of "remove the file", if the user submits the form without36// touching it.3738// This also allows the input to "hold" the value of an uploaded file if39// there is another error in the form: when you submit the form but are40// stopped because of an unrelated error, submitting it again will keep41// the value around (if you don't upload a new file) instead of requiring42// you to pick the file again.4344// TODO: This works alright, but is a bit of a hack, and the UI should45// provide the user better feedback about whether the state of the control46// is "keep the value the same" or "remove the value", and about whether47// or not the control is "holding" a value from a previous submission.4849$default_input = null;50$default_value = $this->getValue();51if ($default_value !== null) {52$default_input = phutil_tag(53'input',54array(55'type' => 'hidden',56'name' => $this->getName().'_default',57'value' => $default_value,58));59}6061return array(62phutil_tag(63'input',64array(65'type' => 'file',66'multiple' => $this->getAllowMultiple() ? 'multiple' : null,67'name' => $this->getName().'_raw',68'id' => $file_id,69'disabled' => $this->getDisabled() ? 'disabled' : null,70)),71$default_input,72);73}7475}767778