diff --git a/src/applications/differential/customfield/DifferentialCoreCustomField.php b/src/applications/differential/customfield/DifferentialCoreCustomField.php index a63ffca7bb..7333857ce7 100644 --- a/src/applications/differential/customfield/DifferentialCoreCustomField.php +++ b/src/applications/differential/customfield/DifferentialCoreCustomField.php @@ -79,7 +79,7 @@ abstract class DifferentialCoreCustomField return true; } - protected function didSetObject(PhabricatorCustomFieldInterface $object) { + public function readValueFromObject(PhabricatorCustomFieldInterface $object) { if ($this->isCoreFieldRequired()) { $this->setFieldError(true); } diff --git a/src/applications/maniphest/controller/ManiphestTaskDetailController.php b/src/applications/maniphest/controller/ManiphestTaskDetailController.php index 3964730788..a93846a615 100644 --- a/src/applications/maniphest/controller/ManiphestTaskDetailController.php +++ b/src/applications/maniphest/controller/ManiphestTaskDetailController.php @@ -47,15 +47,9 @@ final class ManiphestTaskDetailController extends ManiphestController { $field_list = PhabricatorCustomField::getObjectFields( $task, PhabricatorCustomField::ROLE_VIEW); - - foreach ($field_list->getFields() as $field) { - $field->setObject($task); - $field->setViewer($user); - } - - $field_list->readFieldsFromStorage($task); - - $aux_fields = $field_list->getFields(); + $field_list + ->setViewer($user) + ->readFieldsFromStorage($task); $e_commit = PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT; $e_dep_on = PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK; diff --git a/src/applications/maniphest/controller/ManiphestTaskEditController.php b/src/applications/maniphest/controller/ManiphestTaskEditController.php index ecdbae0829..294ff07248 100644 --- a/src/applications/maniphest/controller/ManiphestTaskEditController.php +++ b/src/applications/maniphest/controller/ManiphestTaskEditController.php @@ -158,11 +158,6 @@ final class ManiphestTaskEditController extends ManiphestController { $task, PhabricatorCustomField::ROLE_EDIT); $field_list->setViewer($user); - - foreach ($field_list->getFields() as $field) { - $field->setObject($task); - } - $field_list->readFieldsFromStorage($task); $aux_fields = $field_list->getFields(); @@ -389,6 +384,7 @@ final class ManiphestTaskEditController extends ManiphestController { if ($fields) { id(new PhabricatorCustomFieldList($fields)) + ->setViewer($user) ->readFieldsFromStorage($template_task); foreach ($fields as $key => $field) { diff --git a/src/applications/people/customfield/PhabricatorUserBlurbField.php b/src/applications/people/customfield/PhabricatorUserBlurbField.php index 5e9c5627f8..8cdb100225 100644 --- a/src/applications/people/customfield/PhabricatorUserBlurbField.php +++ b/src/applications/people/customfield/PhabricatorUserBlurbField.php @@ -29,7 +29,7 @@ final class PhabricatorUserBlurbField return true; } - protected function didSetObject(PhabricatorCustomFieldInterface $object) { + public function readValueFromObject(PhabricatorCustomFieldInterface $object) { $this->value = $object->loadUserProfile()->getBlurb(); } diff --git a/src/applications/people/customfield/PhabricatorUserRealNameField.php b/src/applications/people/customfield/PhabricatorUserRealNameField.php index 87a062d211..90e490fc3b 100644 --- a/src/applications/people/customfield/PhabricatorUserRealNameField.php +++ b/src/applications/people/customfield/PhabricatorUserRealNameField.php @@ -29,7 +29,7 @@ final class PhabricatorUserRealNameField return true; } - protected function didSetObject(PhabricatorCustomFieldInterface $object) { + public function readValueFromObject(PhabricatorCustomFieldInterface $object) { $this->value = $object->getRealName(); } diff --git a/src/applications/people/customfield/PhabricatorUserTitleField.php b/src/applications/people/customfield/PhabricatorUserTitleField.php index 472abe1639..6e13b93aa7 100644 --- a/src/applications/people/customfield/PhabricatorUserTitleField.php +++ b/src/applications/people/customfield/PhabricatorUserTitleField.php @@ -29,7 +29,7 @@ final class PhabricatorUserTitleField return true; } - protected function didSetObject(PhabricatorCustomFieldInterface $object) { + public function readValueFromObject(PhabricatorCustomFieldInterface $object) { $this->value = $object->loadUserProfile()->getTitle(); } diff --git a/src/infrastructure/customfield/field/PhabricatorCustomField.php b/src/infrastructure/customfield/field/PhabricatorCustomField.php index 56f48e889f..133bf382b8 100644 --- a/src/infrastructure/customfield/field/PhabricatorCustomField.php +++ b/src/infrastructure/customfield/field/PhabricatorCustomField.php @@ -347,6 +347,7 @@ abstract class PhabricatorCustomField { * Sets the object this field belongs to. * * @param PhabricatorCustomFieldInterface The object this field belongs to. + * @return this * @task context */ final public function setObject(PhabricatorCustomFieldInterface $object) { @@ -361,6 +362,21 @@ abstract class PhabricatorCustomField { } + /** + * Read object data into local field storage, if applicable. + * + * @param PhabricatorCustomFieldInterface The object this field belongs to. + * @return this + * @task context + */ + public function readValueFromObject(PhabricatorCustomFieldInterface $object) { + if ($this->proxy) { + $this->proxy->readValueFromObject($object); + } + return $this; + } + + /** * Get the object this field belongs to. * diff --git a/src/infrastructure/customfield/field/PhabricatorCustomFieldList.php b/src/infrastructure/customfield/field/PhabricatorCustomFieldList.php index d5623771dd..ffe96bc285 100644 --- a/src/infrastructure/customfield/field/PhabricatorCustomFieldList.php +++ b/src/infrastructure/customfield/field/PhabricatorCustomFieldList.php @@ -39,6 +39,11 @@ final class PhabricatorCustomFieldList extends Phobject { public function readFieldsFromStorage( PhabricatorCustomFieldInterface $object) { + foreach ($this->fields as $field) { + $field->setObject($object); + $field->readValueFromObject($object); + } + $keys = array(); foreach ($this->fields as $field) { if ($field->shouldEnableForRole(PhabricatorCustomField::ROLE_STORAGE)) { diff --git a/src/view/form/control/AphrontFormPolicyControl.php b/src/view/form/control/AphrontFormPolicyControl.php index b926f8b4f3..31b0798f8b 100644 --- a/src/view/form/control/AphrontFormPolicyControl.php +++ b/src/view/form/control/AphrontFormPolicyControl.php @@ -180,7 +180,9 @@ final class AphrontFormPolicyControl extends AphrontFormControl { 'customPlaceholder' => $this->getCustomPolicyPlaceholder(), )); - $selected = $flat_options[$this->getValue()]; + $selected = idx($flat_options, $this->getValue(), array()); + $selected_icon = idx($selected, 'icon'); + $selected_name = idx($selected, 'name'); return phutil_tag( 'div', @@ -205,8 +207,8 @@ final class AphrontFormPolicyControl extends AphrontFormControl { 'class' => 'phui-button-text', ), array( - $icons[$selected['icon']], - $selected['name'], + idx($icons, $selected_icon), + $selected_name, )), )), $input,