Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/customfield/field/PhabricatorCustomFieldList.php
<?php | <?php | ||||
/** | /** | ||||
* Convenience class to perform operations on an entire field list, like reading | * Convenience class to perform operations on an entire field list, like reading | ||||
* all values from storage. | * all values from storage. | ||||
* | * | ||||
* $field_list = new PhabricatorCustomFieldList($fields); | * $field_list = new PhabricatorCustomFieldList($fields); | ||||
* | * | ||||
*/ | */ | ||||
final class PhabricatorCustomFieldList extends Phobject { | final class PhabricatorCustomFieldList extends Phobject { | ||||
private $fields; | private $fields; | ||||
private $viewer; | |||||
public function __construct(array $fields) { | public function __construct(array $fields) { | ||||
assert_instances_of($fields, 'PhabricatorCustomField'); | assert_instances_of($fields, 'PhabricatorCustomField'); | ||||
$this->fields = $fields; | $this->fields = $fields; | ||||
} | } | ||||
public function getFields() { | public function getFields() { | ||||
return $this->fields; | return $this->fields; | ||||
} | } | ||||
public function setViewer(PhabricatorUser $viewer) { | public function setViewer(PhabricatorUser $viewer) { | ||||
$this->viewer = $viewer; | |||||
foreach ($this->getFields() as $field) { | foreach ($this->getFields() as $field) { | ||||
$field->setViewer($viewer); | $field->setViewer($viewer); | ||||
} | } | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | /** | ||||
Show All 38 Lines | foreach ($keys as $key => $field) { | ||||
// NOTE: We set this only if the object exists. Otherwise, we allow the | // NOTE: We set this only if the object exists. Otherwise, we allow the | ||||
// field to retain any default value it may have. | // field to retain any default value it may have. | ||||
$field->setValueFromStorage(null); | $field->setValueFromStorage(null); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public function appendFieldsToForm(AphrontFormView $form) { | public function appendFieldsToForm(AphrontFormView $form) { | ||||
$enabled = array(); | |||||
foreach ($this->fields as $field) { | foreach ($this->fields as $field) { | ||||
if ($field->shouldEnableForRole(PhabricatorCustomField::ROLE_EDIT)) { | if ($field->shouldEnableForRole(PhabricatorCustomField::ROLE_EDIT)) { | ||||
$form->appendChild($field->renderEditControl()); | $enabled[] = $field; | ||||
} | } | ||||
} | } | ||||
$phids = array(); | |||||
foreach ($enabled as $field_key => $field) { | |||||
$phids[$field_key] = $field->getRequiredHandlePHIDsForEdit(); | |||||
} | |||||
$all_phids = array_mergev($phids); | |||||
if ($all_phids) { | |||||
$handles = id(new PhabricatorHandleQuery()) | |||||
->setViewer($this->viewer) | |||||
->withPHIDs($all_phids) | |||||
->execute(); | |||||
} else { | |||||
$handles = array(); | |||||
} | |||||
foreach ($enabled as $field_key => $field) { | |||||
$field_handles = array_select_keys($handles, $phids[$field_key]); | |||||
$form->appendChild($field->renderEditControl($field_handles)); | |||||
} | |||||
} | } | ||||
public function appendFieldsToPropertyList( | public function appendFieldsToPropertyList( | ||||
PhabricatorCustomFieldInterface $object, | PhabricatorCustomFieldInterface $object, | ||||
PhabricatorUser $viewer, | PhabricatorUser $viewer, | ||||
PHUIPropertyListView $view) { | PHUIPropertyListView $view) { | ||||
$this->readFieldsFromStorage($object); | $this->readFieldsFromStorage($object); | ||||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |