Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/view/form/control/PHUIFormFileControl.php
13400 views
1
<?php
2
3
final class PHUIFormFileControl
4
extends AphrontFormControl {
5
6
private $allowMultiple;
7
8
protected function getCustomControlClass() {
9
return 'phui-form-file-upload';
10
}
11
12
public function setAllowMultiple($allow_multiple) {
13
$this->allowMultiple = $allow_multiple;
14
return $this;
15
}
16
17
public function getAllowMultiple() {
18
return $this->allowMultiple;
19
}
20
21
protected function renderInput() {
22
$file_id = $this->getID();
23
24
Javelin::initBehavior(
25
'phui-file-upload',
26
array(
27
'fileInputID' => $file_id,
28
'inputName' => $this->getName(),
29
'uploadURI' => '/file/dropupload/',
30
'chunkThreshold' => PhabricatorFileStorageEngine::getChunkThreshold(),
31
));
32
33
34
// If the control has a value, add a hidden input which submits it as a
35
// default. This allows the file control to mean "don't change anything",
36
// instead of "remove the file", if the user submits the form without
37
// touching it.
38
39
// This also allows the input to "hold" the value of an uploaded file if
40
// there is another error in the form: when you submit the form but are
41
// stopped because of an unrelated error, submitting it again will keep
42
// the value around (if you don't upload a new file) instead of requiring
43
// you to pick the file again.
44
45
// TODO: This works alright, but is a bit of a hack, and the UI should
46
// provide the user better feedback about whether the state of the control
47
// is "keep the value the same" or "remove the value", and about whether
48
// or not the control is "holding" a value from a previous submission.
49
50
$default_input = null;
51
$default_value = $this->getValue();
52
if ($default_value !== null) {
53
$default_input = phutil_tag(
54
'input',
55
array(
56
'type' => 'hidden',
57
'name' => $this->getName().'_default',
58
'value' => $default_value,
59
));
60
}
61
62
return array(
63
phutil_tag(
64
'input',
65
array(
66
'type' => 'file',
67
'multiple' => $this->getAllowMultiple() ? 'multiple' : null,
68
'name' => $this->getName().'_raw',
69
'id' => $file_id,
70
'disabled' => $this->getDisabled() ? 'disabled' : null,
71
)),
72
$default_input,
73
);
74
}
75
76
}
77
78