@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.

Separate reading object values out of didSetObject() in CustomField

Summary:
Ref T3886. Broadly, fields break down into two types right now: fields which store data on the object (like `DifferentialTitleField`) and fields which store data in custom field storage.

The former type generally reads data from the object into local storage prior to editing, then writes it back afterward. Currently, this happens in `didSetObject()`.

However, now that we load and set objects from ApplicationTransactionQuery, we'll do this extra read-field-values on view interfaces too. There, it's unnecessary and sometimes throws data-attached exceptions.

Instead, separate these concepts, and do all the read-from-object / read-from-storage in one logical chunk, separate from `didSetObject()`.

Test Plan:
- Edited Differential revision.
- Edited Maniphest task.
- Edited Project.
- Edited user profile.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3886

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

+34 -21
+1 -1
src/applications/differential/customfield/DifferentialCoreCustomField.php
··· 79 79 return true; 80 80 } 81 81 82 - protected function didSetObject(PhabricatorCustomFieldInterface $object) { 82 + public function readValueFromObject(PhabricatorCustomFieldInterface $object) { 83 83 if ($this->isCoreFieldRequired()) { 84 84 $this->setFieldError(true); 85 85 }
+3 -9
src/applications/maniphest/controller/ManiphestTaskDetailController.php
··· 47 47 $field_list = PhabricatorCustomField::getObjectFields( 48 48 $task, 49 49 PhabricatorCustomField::ROLE_VIEW); 50 - 51 - foreach ($field_list->getFields() as $field) { 52 - $field->setObject($task); 53 - $field->setViewer($user); 54 - } 55 - 56 - $field_list->readFieldsFromStorage($task); 57 - 58 - $aux_fields = $field_list->getFields(); 50 + $field_list 51 + ->setViewer($user) 52 + ->readFieldsFromStorage($task); 59 53 60 54 $e_commit = PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT; 61 55 $e_dep_on = PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK;
+1 -5
src/applications/maniphest/controller/ManiphestTaskEditController.php
··· 158 158 $task, 159 159 PhabricatorCustomField::ROLE_EDIT); 160 160 $field_list->setViewer($user); 161 - 162 - foreach ($field_list->getFields() as $field) { 163 - $field->setObject($task); 164 - } 165 - 166 161 $field_list->readFieldsFromStorage($task); 167 162 168 163 $aux_fields = $field_list->getFields(); ··· 389 384 390 385 if ($fields) { 391 386 id(new PhabricatorCustomFieldList($fields)) 387 + ->setViewer($user) 392 388 ->readFieldsFromStorage($template_task); 393 389 394 390 foreach ($fields as $key => $field) {
+1 -1
src/applications/people/customfield/PhabricatorUserBlurbField.php
··· 29 29 return true; 30 30 } 31 31 32 - protected function didSetObject(PhabricatorCustomFieldInterface $object) { 32 + public function readValueFromObject(PhabricatorCustomFieldInterface $object) { 33 33 $this->value = $object->loadUserProfile()->getBlurb(); 34 34 } 35 35
+1 -1
src/applications/people/customfield/PhabricatorUserRealNameField.php
··· 29 29 return true; 30 30 } 31 31 32 - protected function didSetObject(PhabricatorCustomFieldInterface $object) { 32 + public function readValueFromObject(PhabricatorCustomFieldInterface $object) { 33 33 $this->value = $object->getRealName(); 34 34 } 35 35
+1 -1
src/applications/people/customfield/PhabricatorUserTitleField.php
··· 29 29 return true; 30 30 } 31 31 32 - protected function didSetObject(PhabricatorCustomFieldInterface $object) { 32 + public function readValueFromObject(PhabricatorCustomFieldInterface $object) { 33 33 $this->value = $object->loadUserProfile()->getTitle(); 34 34 } 35 35
+16
src/infrastructure/customfield/field/PhabricatorCustomField.php
··· 347 347 * Sets the object this field belongs to. 348 348 * 349 349 * @param PhabricatorCustomFieldInterface The object this field belongs to. 350 + * @return this 350 351 * @task context 351 352 */ 352 353 final public function setObject(PhabricatorCustomFieldInterface $object) { ··· 357 358 358 359 $this->object = $object; 359 360 $this->didSetObject($object); 361 + return $this; 362 + } 363 + 364 + 365 + /** 366 + * Read object data into local field storage, if applicable. 367 + * 368 + * @param PhabricatorCustomFieldInterface The object this field belongs to. 369 + * @return this 370 + * @task context 371 + */ 372 + public function readValueFromObject(PhabricatorCustomFieldInterface $object) { 373 + if ($this->proxy) { 374 + $this->proxy->readValueFromObject($object); 375 + } 360 376 return $this; 361 377 } 362 378
+5
src/infrastructure/customfield/field/PhabricatorCustomFieldList.php
··· 39 39 public function readFieldsFromStorage( 40 40 PhabricatorCustomFieldInterface $object) { 41 41 42 + foreach ($this->fields as $field) { 43 + $field->setObject($object); 44 + $field->readValueFromObject($object); 45 + } 46 + 42 47 $keys = array(); 43 48 foreach ($this->fields as $field) { 44 49 if ($field->shouldEnableForRole(PhabricatorCustomField::ROLE_STORAGE)) {
+5 -3
src/view/form/control/AphrontFormPolicyControl.php
··· 180 180 'customPlaceholder' => $this->getCustomPolicyPlaceholder(), 181 181 )); 182 182 183 - $selected = $flat_options[$this->getValue()]; 183 + $selected = idx($flat_options, $this->getValue(), array()); 184 + $selected_icon = idx($selected, 'icon'); 185 + $selected_name = idx($selected, 'name'); 184 186 185 187 return phutil_tag( 186 188 'div', ··· 205 207 'class' => 'phui-button-text', 206 208 ), 207 209 array( 208 - $icons[$selected['icon']], 209 - $selected['name'], 210 + idx($icons, $selected_icon), 211 + $selected_name, 210 212 )), 211 213 )), 212 214 $input,