@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 110 lines 2.9 kB view raw
1<?php 2 3final class AphrontFormTextControl extends AphrontFormControl { 4 5 private $disableAutocomplete; 6 private $sigil; 7 private $placeholder; 8 private $autofocus; 9 private $readOnly; 10 11 public function setDisableAutocomplete($disable) { 12 $this->disableAutocomplete = $disable; 13 return $this; 14 } 15 16 private function getDisableAutocomplete() { 17 return $this->disableAutocomplete; 18 } 19 20 public function getPlaceholder() { 21 return $this->placeholder; 22 } 23 24 public function setPlaceholder($placeholder) { 25 $this->placeholder = $placeholder; 26 return $this; 27 } 28 29 public function setAutofocus($autofocus) { 30 $this->autofocus = $autofocus; 31 return $this; 32 } 33 34 public function getAutofocus() { 35 return $this->autofocus; 36 } 37 38 public function getSigil() { 39 return $this->sigil; 40 } 41 42 public function setSigil($sigil) { 43 $this->sigil = $sigil; 44 return $this; 45 } 46 47 public function setReadOnly($read_only) { 48 $this->readOnly = $read_only; 49 return $this; 50 } 51 52 protected function getReadOnly() { 53 return $this->readOnly; 54 } 55 56 protected function getCustomControlClass() { 57 return 'aphront-form-control-text'; 58 } 59 60 protected function renderInput() { 61 $input = array(); 62 $input[] = javelin_tag( 63 'input', 64 array( 65 'type' => 'text', 66 'name' => $this->getName(), 67 'value' => $this->getValue(), 68 'disabled' => $this->getDisabled() ? 'disabled' : null, 69 'readonly' => $this->getReadOnly() ? 'readonly' : null, 70 'autocomplete' => $this->getDisableAutocomplete() ? 'off' : null, 71 'id' => $this->getID(), 72 'sigil' => $this->getSigil(), 73 'placeholder' => $this->getPlaceholder(), 74 'autofocus' => ($this->getAutofocus() ? 'autofocus' : null), 75 )); 76 77 if ($this->getHasCopyButton()) { 78 Javelin::initBehavior('select-content'); 79 Javelin::initBehavior('phabricator-clipboard-copy'); 80 Javelin::initBehavior('phabricator-tooltips'); 81 82 $field_label = $this->getLabel(); 83 if (phutil_nonempty_string($field_label)) { 84 // TODO: 'Copy %s' is broken i18n as it ignores grammatical case 85 $tip_message = pht('Copy %s', $field_label); 86 $success_message = pht('%s copied.', $field_label); 87 } else { 88 $tip_message = pht('Copy text'); 89 $success_message = pht('Text copied.'); 90 } 91 $copy = id(new PHUIButtonView()) 92 ->setTag('a') 93 ->setColor(PHUIButtonView::GREY) 94 ->setIcon('fa-clipboard') 95 ->setHref('#') 96 ->addSigil('clipboard-copy') 97 ->addSigil('has-tooltip') 98 ->setMetadata( 99 array( 100 'tip' => $tip_message, 101 'text' => $this->getValue(), 102 'successMessage' => $success_message, 103 'errorMessage' => pht('Copying failed.'), 104 )); 105 $input[] = $copy; 106 } 107 return $input; 108 } 109 110}