@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove old paged forms

Summary:
Ref T11326. This gets rid of the old multi-paged form stuff used in the last version of Diffusion.

This incidentally removes a callsite for a date control to make it a little easier to simplify them.

Test Plan: Grepped for all removed classes, no more callsites.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11326

Differential Revision: https://secure.phabricator.com/D16302

-656
-8
src/__phutil_library_map__.php
··· 1626 1626 'PHUIFormIconSetControl' => 'view/form/control/PHUIFormIconSetControl.php', 1627 1627 'PHUIFormInsetView' => 'view/form/PHUIFormInsetView.php', 1628 1628 'PHUIFormLayoutView' => 'view/form/PHUIFormLayoutView.php', 1629 - 'PHUIFormMultiSubmitControl' => 'view/form/control/PHUIFormMultiSubmitControl.php', 1630 - 'PHUIFormPageView' => 'view/form/PHUIFormPageView.php', 1631 1629 'PHUIHandleListView' => 'applications/phid/view/PHUIHandleListView.php', 1632 1630 'PHUIHandleTagListView' => 'applications/phid/view/PHUIHandleTagListView.php', 1633 1631 'PHUIHandleView' => 'applications/phid/view/PHUIHandleView.php', ··· 1653 1651 'PHUIObjectItemListExample' => 'applications/uiexample/examples/PHUIObjectItemListExample.php', 1654 1652 'PHUIObjectItemListView' => 'view/phui/PHUIObjectItemListView.php', 1655 1653 'PHUIObjectItemView' => 'view/phui/PHUIObjectItemView.php', 1656 - 'PHUIPagedFormView' => 'view/form/PHUIPagedFormView.php', 1657 1654 'PHUIPagerView' => 'view/phui/PHUIPagerView.php', 1658 1655 'PHUIPinboardItemView' => 'view/phui/PHUIPinboardItemView.php', 1659 1656 'PHUIPinboardView' => 'view/phui/PHUIPinboardView.php', ··· 2974 2971 'PhabricatorPHPASTApplication' => 'applications/phpast/application/PhabricatorPHPASTApplication.php', 2975 2972 'PhabricatorPHPConfigSetupCheck' => 'applications/config/check/PhabricatorPHPConfigSetupCheck.php', 2976 2973 'PhabricatorPHPMailerConfigOptions' => 'applications/config/option/PhabricatorPHPMailerConfigOptions.php', 2977 - 'PhabricatorPagedFormUIExample' => 'applications/uiexample/examples/PhabricatorPagedFormUIExample.php', 2978 2974 'PhabricatorPagerUIExample' => 'applications/uiexample/examples/PhabricatorPagerUIExample.php', 2979 2975 'PhabricatorPassphraseApplication' => 'applications/passphrase/application/PhabricatorPassphraseApplication.php', 2980 2976 'PhabricatorPasswordAuthProvider' => 'applications/auth/provider/PhabricatorPasswordAuthProvider.php', ··· 6189 6185 'PHUIFormIconSetControl' => 'AphrontFormControl', 6190 6186 'PHUIFormInsetView' => 'AphrontView', 6191 6187 'PHUIFormLayoutView' => 'AphrontView', 6192 - 'PHUIFormMultiSubmitControl' => 'AphrontFormControl', 6193 - 'PHUIFormPageView' => 'AphrontView', 6194 6188 'PHUIHandleListView' => 'AphrontTagView', 6195 6189 'PHUIHandleTagListView' => 'AphrontTagView', 6196 6190 'PHUIHandleView' => 'AphrontView', ··· 6216 6210 'PHUIObjectItemListExample' => 'PhabricatorUIExample', 6217 6211 'PHUIObjectItemListView' => 'AphrontTagView', 6218 6212 'PHUIObjectItemView' => 'AphrontTagView', 6219 - 'PHUIPagedFormView' => 'AphrontView', 6220 6213 'PHUIPagerView' => 'AphrontView', 6221 6214 'PHUIPinboardItemView' => 'AphrontView', 6222 6215 'PHUIPinboardView' => 'AphrontView', ··· 7730 7723 'PhabricatorPHPASTApplication' => 'PhabricatorApplication', 7731 7724 'PhabricatorPHPConfigSetupCheck' => 'PhabricatorSetupCheck', 7732 7725 'PhabricatorPHPMailerConfigOptions' => 'PhabricatorApplicationConfigOptions', 7733 - 'PhabricatorPagedFormUIExample' => 'PhabricatorUIExample', 7734 7726 'PhabricatorPagerUIExample' => 'PhabricatorUIExample', 7735 7727 'PhabricatorPassphraseApplication' => 'PhabricatorApplication', 7736 7728 'PhabricatorPasswordAuthProvider' => 'PhabricatorAuthProvider',
-71
src/applications/uiexample/examples/PhabricatorPagedFormUIExample.php
··· 1 - <?php 2 - 3 - final class PhabricatorPagedFormUIExample extends PhabricatorUIExample { 4 - 5 - public function getName() { 6 - return pht('Form (Paged)'); 7 - } 8 - 9 - public function getDescription() { 10 - return pht( 11 - 'Use %s to render forms with multiple pages.', 12 - hsprintf('<tt>PHUIPagedFormView</tt>')); 13 - } 14 - 15 - public function renderExample() { 16 - $request = $this->getRequest(); 17 - $user = $request->getUser(); 18 - 19 - 20 - $page1 = id(new PHUIFormPageView()) 21 - ->setPageName(pht('Page 1')) 22 - ->addControl( 23 - id(new AphrontFormTextControl()) 24 - ->setName('page1') 25 - ->setLabel(pht('Page 1'))); 26 - 27 - $page2 = id(new PHUIFormPageView()) 28 - ->setPageName(pht('Page 2')) 29 - ->addControl( 30 - id(new AphrontFormTextControl()) 31 - ->setName('page2') 32 - ->setLabel(pht('Page 2'))); 33 - 34 - $page3 = id(new PHUIFormPageView()) 35 - ->setPageName(pht('Page 3')) 36 - ->addControl( 37 - id(new AphrontFormTextControl()) 38 - ->setName('page3') 39 - ->setLabel(pht('Page 3'))); 40 - 41 - $page4 = id(new PHUIFormPageView()) 42 - ->setPageName(pht('Page 4')) 43 - ->addControl( 44 - id(new AphrontFormTextControl()) 45 - ->setName('page4') 46 - ->setLabel(pht('Page 4'))); 47 - 48 - $form = new PHUIPagedFormView(); 49 - $form->setUser($user); 50 - 51 - $form->addPage('page1', $page1); 52 - $form->addPage('page2', $page2); 53 - $form->addPage('page3', $page3); 54 - $form->addPage('page4', $page4); 55 - 56 - if ($request->isFormPost()) { 57 - $form->readFromRequest($request); 58 - if ($form->isComplete()) { 59 - return id(new AphrontDialogView()) 60 - ->setUser($user) 61 - ->setTitle(pht('Form Complete')) 62 - ->appendChild(pht('You submitted the form. Well done!')) 63 - ->addCancelButton($request->getRequestURI(), pht('Again!')); 64 - } 65 - } else { 66 - $form->readFromObject(null); 67 - } 68 - 69 - return $form; 70 - } 71 - }
-221
src/view/form/PHUIFormPageView.php
··· 1 - <?php 2 - 3 - /** 4 - * @concrete-extensible 5 - */ 6 - class PHUIFormPageView extends AphrontView { 7 - 8 - private $key; 9 - private $form; 10 - private $controls = array(); 11 - private $content = array(); 12 - private $values = array(); 13 - private $isValid; 14 - private $validateFormPageCallback; 15 - private $adjustFormPageCallback; 16 - private $pageErrors = array(); 17 - private $pageName; 18 - 19 - 20 - public function setPageName($page_name) { 21 - $this->pageName = $page_name; 22 - return $this; 23 - } 24 - 25 - public function getPageName() { 26 - return $this->pageName; 27 - } 28 - 29 - public function addPageError($page_error) { 30 - $this->pageErrors[] = $page_error; 31 - return $this; 32 - } 33 - 34 - public function getPageErrors() { 35 - return $this->pageErrors; 36 - } 37 - 38 - public function setAdjustFormPageCallback($adjust_form_page_callback) { 39 - $this->adjustFormPageCallback = $adjust_form_page_callback; 40 - return $this; 41 - } 42 - 43 - public function setValidateFormPageCallback($validate_form_page_callback) { 44 - $this->validateFormPageCallback = $validate_form_page_callback; 45 - return $this; 46 - } 47 - 48 - public function addInstructions($text, $before = null) { 49 - $tag = phutil_tag( 50 - 'div', 51 - array( 52 - 'class' => 'aphront-form-instructions', 53 - ), 54 - $text); 55 - 56 - $append = true; 57 - if ($before !== null) { 58 - for ($ii = 0; $ii < count($this->content); $ii++) { 59 - if ($this->content[$ii] instanceof AphrontFormControl) { 60 - if ($this->content[$ii]->getName() == $before) { 61 - array_splice($this->content, $ii, 0, array($tag)); 62 - $append = false; 63 - break; 64 - } 65 - } 66 - } 67 - } 68 - 69 - if ($append) { 70 - $this->content[] = $tag; 71 - } 72 - 73 - return $this; 74 - } 75 - 76 - public function addRemarkupInstructions($remarkup, $before = null) { 77 - $remarkup = new PHUIRemarkupView($this->getUser(), $remarkup); 78 - return $this->addInstructions($remarkup, $before); 79 - } 80 - 81 - public function addControl(AphrontFormControl $control) { 82 - $name = $control->getName(); 83 - 84 - if (!strlen($name)) { 85 - throw new Exception(pht('Form control has no name!')); 86 - } 87 - 88 - if (isset($this->controls[$name])) { 89 - throw new Exception( 90 - pht("Form page contains duplicate control with name '%s'!", $name)); 91 - } 92 - 93 - $this->controls[$name] = $control; 94 - $this->content[] = $control; 95 - $control->setFormPage($this); 96 - 97 - return $this; 98 - } 99 - 100 - public function getControls() { 101 - return $this->controls; 102 - } 103 - 104 - public function getControl($name) { 105 - if (empty($this->controls[$name])) { 106 - throw new Exception(pht("No page control '%s'!", $name)); 107 - } 108 - return $this->controls[$name]; 109 - } 110 - 111 - protected function canAppendChild() { 112 - return false; 113 - } 114 - 115 - public function setPagedFormView(PHUIPagedFormView $view, $key) { 116 - if ($this->key) { 117 - throw new Exception(pht('This page is already part of a form!')); 118 - } 119 - $this->form = $view; 120 - $this->key = $key; 121 - return $this; 122 - } 123 - 124 - public function adjustFormPage() { 125 - if ($this->adjustFormPageCallback) { 126 - call_user_func($this->adjustFormPageCallback, $this); 127 - } 128 - return $this; 129 - } 130 - 131 - protected function validateFormPage() { 132 - if ($this->validateFormPageCallback) { 133 - return call_user_func($this->validateFormPageCallback, $this); 134 - } 135 - return true; 136 - } 137 - 138 - public function getKey() { 139 - return $this->key; 140 - } 141 - 142 - public function render() { 143 - return $this->content; 144 - } 145 - 146 - public function getForm() { 147 - return $this->form; 148 - } 149 - 150 - public function getRequestKey($key) { 151 - return $this->getForm()->getRequestKey('p:'.$this->key.':'.$key); 152 - } 153 - 154 - public function validateObjectType($object) { 155 - return true; 156 - } 157 - 158 - public function validateResponseType($response) { 159 - return true; 160 - } 161 - 162 - protected function validateControls() { 163 - $result = true; 164 - foreach ($this->getControls() as $name => $control) { 165 - if (!$control->isValid()) { 166 - $result = false; 167 - break; 168 - } 169 - } 170 - 171 - return $result; 172 - } 173 - 174 - public function isValid() { 175 - if ($this->isValid === null) { 176 - $this->isValid = $this->validateControls() && $this->validateFormPage(); 177 - } 178 - return $this->isValid; 179 - } 180 - 181 - public function readFromRequest(AphrontRequest $request) { 182 - foreach ($this->getControls() as $name => $control) { 183 - $control->readValueFromRequest($request); 184 - } 185 - 186 - return $this; 187 - } 188 - 189 - public function readFromObject($object) { 190 - foreach ($this->getControls() as $name => $control) { 191 - if (is_array($object)) { 192 - $control->readValueFromDictionary($object); 193 - } 194 - } 195 - 196 - return $this; 197 - } 198 - 199 - public function writeToResponse($response) { 200 - return $this; 201 - } 202 - 203 - public function readSerializedValues(AphrontRequest $request) { 204 - foreach ($this->getControls() as $name => $control) { 205 - $key = $this->getRequestKey($name); 206 - $control->readSerializedValue($request->getStr($key)); 207 - } 208 - 209 - return $this; 210 - } 211 - 212 - public function getSerializedValues() { 213 - $dict = array(); 214 - foreach ($this->getControls() as $name => $control) { 215 - $key = $this->getRequestKey($name); 216 - $dict[$key] = $control->getSerializedValue(); 217 - } 218 - return $dict; 219 - } 220 - 221 - }
-279
src/view/form/PHUIPagedFormView.php
··· 1 - <?php 2 - 3 - /** 4 - * @task page Managing Pages 5 - */ 6 - final class PHUIPagedFormView extends AphrontView { 7 - 8 - private $name = 'pages'; 9 - private $pages = array(); 10 - private $selectedPage; 11 - private $choosePage; 12 - private $nextPage; 13 - private $prevPage; 14 - private $complete; 15 - private $cancelURI; 16 - 17 - protected function canAppendChild() { 18 - return false; 19 - } 20 - 21 - 22 - /* -( Managing Pages )----------------------------------------------------- */ 23 - 24 - 25 - /** 26 - * @task page 27 - */ 28 - public function addPage($key, PHUIFormPageView $page) { 29 - if (isset($this->pages[$key])) { 30 - throw new Exception(pht("Duplicate page with key '%s'!", $key)); 31 - } 32 - $this->pages[$key] = $page; 33 - $page->setPagedFormView($this, $key); 34 - 35 - $this->selectedPage = null; 36 - $this->complete = null; 37 - 38 - return $this; 39 - } 40 - 41 - 42 - /** 43 - * @task page 44 - */ 45 - public function getPage($key) { 46 - if (!$this->pageExists($key)) { 47 - throw new Exception(pht("No page '%s' exists!", $key)); 48 - } 49 - return $this->pages[$key]; 50 - } 51 - 52 - 53 - /** 54 - * @task page 55 - */ 56 - public function pageExists($key) { 57 - return isset($this->pages[$key]); 58 - } 59 - 60 - 61 - /** 62 - * @task page 63 - */ 64 - protected function getPageIndex($key) { 65 - $page = $this->getPage($key); 66 - 67 - $index = 0; 68 - foreach ($this->pages as $target_page) { 69 - if ($page === $target_page) { 70 - break; 71 - } 72 - $index++; 73 - } 74 - 75 - return $index; 76 - } 77 - 78 - 79 - /** 80 - * @task page 81 - */ 82 - protected function getPageByIndex($index) { 83 - foreach ($this->pages as $page) { 84 - if (!$index) { 85 - return $page; 86 - } 87 - $index--; 88 - } 89 - 90 - throw new Exception(pht("Requesting out-of-bounds page '%s'.", $index)); 91 - } 92 - 93 - protected function getLastIndex() { 94 - return count($this->pages) - 1; 95 - } 96 - 97 - protected function isFirstPage(PHUIFormPageView $page) { 98 - return ($this->getPageIndex($page->getKey()) === 0); 99 - 100 - } 101 - 102 - protected function isLastPage(PHUIFormPageView $page) { 103 - return ($this->getPageIndex($page->getKey()) === (count($this->pages) - 1)); 104 - } 105 - 106 - public function getSelectedPage() { 107 - return $this->selectedPage; 108 - } 109 - 110 - public function readFromObject($object) { 111 - return $this->processForm($is_request = false, $object); 112 - } 113 - 114 - public function writeToResponse($response) { 115 - foreach ($this->pages as $page) { 116 - $page->validateResponseType($response); 117 - $response = $page->writeToResponse($page); 118 - } 119 - 120 - return $response; 121 - } 122 - 123 - public function readFromRequest(AphrontRequest $request) { 124 - $this->choosePage = $request->getStr($this->getRequestKey('page')); 125 - $this->nextPage = $request->getStr('__submit__'); 126 - $this->prevPage = $request->getStr('__back__'); 127 - 128 - return $this->processForm($is_request = true, $request); 129 - } 130 - 131 - public function setName($name) { 132 - $this->name = $name; 133 - return $this; 134 - } 135 - 136 - 137 - public function getValue($page, $key, $default = null) { 138 - return $this->getPage($page)->getValue($key, $default); 139 - } 140 - 141 - public function setValue($page, $key, $value) { 142 - $this->getPage($page)->setValue($key, $value); 143 - return $this; 144 - } 145 - 146 - private function processForm($is_request, $source) { 147 - if ($this->pageExists($this->choosePage)) { 148 - $selected = $this->getPage($this->choosePage); 149 - } else { 150 - $selected = $this->getPageByIndex(0); 151 - } 152 - 153 - $is_attempt_complete = false; 154 - if ($this->prevPage) { 155 - $prev_index = $this->getPageIndex($selected->getKey()) - 1; 156 - $index = max(0, $prev_index); 157 - $selected = $this->getPageByIndex($index); 158 - } else if ($this->nextPage) { 159 - $next_index = $this->getPageIndex($selected->getKey()) + 1; 160 - if ($next_index > $this->getLastIndex()) { 161 - $is_attempt_complete = true; 162 - } 163 - $index = min($this->getLastIndex(), $next_index); 164 - $selected = $this->getPageByIndex($index); 165 - } 166 - 167 - $validation_error = false; 168 - $found_selected = false; 169 - foreach ($this->pages as $key => $page) { 170 - if ($is_request) { 171 - if ($key === $this->choosePage) { 172 - $page->readFromRequest($source); 173 - } else { 174 - $page->readSerializedValues($source); 175 - } 176 - } else { 177 - $page->readFromObject($source); 178 - } 179 - 180 - if (!$found_selected) { 181 - $page->adjustFormPage(); 182 - } 183 - 184 - if ($page === $selected) { 185 - $found_selected = true; 186 - } 187 - 188 - if (!$found_selected || $is_attempt_complete) { 189 - if (!$page->isValid()) { 190 - $selected = $page; 191 - $validation_error = true; 192 - break; 193 - } 194 - } 195 - } 196 - 197 - if ($is_attempt_complete && !$validation_error) { 198 - $this->complete = true; 199 - } else { 200 - $this->selectedPage = $selected; 201 - } 202 - 203 - return $this; 204 - } 205 - 206 - public function isComplete() { 207 - return $this->complete; 208 - } 209 - 210 - public function getRequestKey($key) { 211 - return $this->name.':'.$key; 212 - } 213 - 214 - public function setCancelURI($cancel_uri) { 215 - $this->cancelURI = $cancel_uri; 216 - return $this; 217 - } 218 - 219 - public function getCancelURI() { 220 - return $this->cancelURI; 221 - } 222 - 223 - public function render() { 224 - $form = id(new AphrontFormView()) 225 - ->setUser($this->getUser()); 226 - 227 - $selected_page = $this->getSelectedPage(); 228 - if (!$selected_page) { 229 - throw new Exception(pht('No selected page!')); 230 - } 231 - 232 - $form->addHiddenInput( 233 - $this->getRequestKey('page'), 234 - $selected_page->getKey()); 235 - 236 - $errors = array(); 237 - 238 - foreach ($this->pages as $page) { 239 - if ($page == $selected_page) { 240 - $errors = $page->getPageErrors(); 241 - continue; 242 - } 243 - foreach ($page->getSerializedValues() as $key => $value) { 244 - $form->addHiddenInput($key, $value); 245 - } 246 - } 247 - 248 - $submit = id(new PHUIFormMultiSubmitControl()); 249 - 250 - if (!$this->isFirstPage($selected_page)) { 251 - $submit->addBackButton(); 252 - } else if ($this->getCancelURI()) { 253 - $submit->addCancelButton($this->getCancelURI()); 254 - } 255 - 256 - if ($this->isLastPage($selected_page)) { 257 - $submit->addSubmitButton(pht('Save')); 258 - } else { 259 - $submit->addSubmitButton(pht('Continue')." \xC2\xBB"); 260 - } 261 - 262 - $form->appendChild($selected_page); 263 - $form->appendChild($submit); 264 - 265 - $box = id(new PHUIObjectBoxView()) 266 - ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 267 - ->setFormErrors($errors) 268 - ->setForm($form); 269 - 270 - if ($selected_page->getPageName()) { 271 - $header = id(new PHUIHeaderView()) 272 - ->setHeader($selected_page->getPageName()); 273 - $box->setHeader($header); 274 - } 275 - 276 - return $box; 277 - } 278 - 279 - }
-16
src/view/form/control/AphrontFormControl.php
··· 11 11 private $id; 12 12 private $controlID; 13 13 private $controlStyle; 14 - private $formPage; 15 14 private $required; 16 15 private $hidden; 17 16 private $classes; ··· 130 129 public function readValueFromDictionary(array $dictionary) { 131 130 $this->setValue(idx($dictionary, $this->getName())); 132 131 return $this; 133 - } 134 - 135 - public function setFormPage(PHUIFormPageView $page) { 136 - if ($this->formPage) { 137 - throw new Exception(pht('This control is already a member of a page!')); 138 - } 139 - $this->formPage = $page; 140 - return $this; 141 - } 142 - 143 - public function getFormPage() { 144 - if ($this->formPage === null) { 145 - throw new Exception(pht('This control does not have a page!')); 146 - } 147 - return $this->formPage; 148 132 } 149 133 150 134 public function setDisabled($disabled) {
-61
src/view/form/control/PHUIFormMultiSubmitControl.php
··· 1 - <?php 2 - 3 - final class PHUIFormMultiSubmitControl extends AphrontFormControl { 4 - 5 - private $buttons = array(); 6 - 7 - public function addBackButton($label = null) { 8 - if ($label === null) { 9 - $label = "\xC2\xAB ".pht('Back'); 10 - } 11 - return $this->addButton('__back__', $label, 'grey'); 12 - } 13 - 14 - public function addSubmitButton($label) { 15 - return $this->addButton('__submit__', $label); 16 - } 17 - 18 - public function addCancelButton($uri, $label = null) { 19 - if ($label === null) { 20 - $label = pht('Cancel'); 21 - } 22 - 23 - $this->buttons[] = phutil_tag( 24 - 'a', 25 - array( 26 - 'class' => 'grey button', 27 - 'href' => $uri, 28 - ), 29 - $label); 30 - 31 - return $this; 32 - } 33 - 34 - public function addButtonView(PHUIButtonView $button) { 35 - $this->buttons[] = $button; 36 - return $this; 37 - } 38 - 39 - public function addButton($name, $label, $class = null) { 40 - $this->buttons[] = javelin_tag( 41 - 'input', 42 - array( 43 - 'type' => 'submit', 44 - 'name' => $name, 45 - 'value' => $label, 46 - 'class' => $class, 47 - 'sigil' => 'alternate-submit-button', 48 - 'disabled' => $this->getDisabled() ? 'disabled' : null, 49 - )); 50 - return $this; 51 - } 52 - 53 - protected function getCustomControlClass() { 54 - return 'phui-form-control-multi-submit'; 55 - } 56 - 57 - protected function renderInput() { 58 - return array_reverse($this->buttons); 59 - } 60 - 61 - }