Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2893014
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
12 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php
index a96ebefda1..48d5ea725a 100644
--- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php
+++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php
@@ -1,275 +1,275 @@
<?php
/**
* Common code for standard field types which store lists of PHIDs.
*/
abstract class PhabricatorStandardCustomFieldPHIDs
extends PhabricatorStandardCustomField {
public function buildFieldIndexes() {
$indexes = array();
$value = $this->getFieldValue();
if (is_array($value)) {
foreach ($value as $phid) {
$indexes[] = $this->newStringIndex($phid);
}
}
return $indexes;
}
public function readValueFromRequest(AphrontRequest $request) {
$value = $request->getArr($this->getFieldKey());
$this->setFieldValue($value);
}
public function getValueForStorage() {
$value = $this->getFieldValue();
if (!$value) {
return null;
}
return json_encode(array_values($value));
}
public function setValueFromStorage($value) {
// NOTE: We're accepting either a JSON string (a real storage value) or
// an array (from HTTP parameter prefilling). This is a little hacky, but
// should hold until this can get cleaned up more thoroughly.
// TODO: Clean this up.
$result = array();
- if (!is_array($value)) {
+ if (!is_array($value) && phutil_nonempty_string($value)) {
$value = json_decode($value, true);
if (is_array($value)) {
$result = array_values($value);
}
}
$this->setFieldValue($value);
return $this;
}
public function readApplicationSearchValueFromRequest(
PhabricatorApplicationSearchEngine $engine,
AphrontRequest $request) {
return $request->getArr($this->getFieldKey());
}
public function applyApplicationSearchConstraintToQuery(
PhabricatorApplicationSearchEngine $engine,
PhabricatorCursorPagedPolicyAwareQuery $query,
$value) {
if ($value) {
$query->withApplicationSearchContainsConstraint(
$this->newStringIndex(null),
$value);
}
}
public function getRequiredHandlePHIDsForPropertyView() {
$value = $this->getFieldValue();
if ($value) {
return $value;
}
return array();
}
public function renderPropertyViewValue(array $handles) {
$value = $this->getFieldValue();
if (!$value) {
return null;
}
$handles = mpull($handles, 'renderHovercardLink');
$handles = phutil_implode_html(', ', $handles);
return $handles;
}
public function getRequiredHandlePHIDsForEdit() {
$value = $this->getFieldValue();
if ($value) {
return $value;
} else {
return array();
}
}
public function getApplicationTransactionRequiredHandlePHIDs(
PhabricatorApplicationTransaction $xaction) {
$old = $this->decodeValue($xaction->getOldValue());
$new = $this->decodeValue($xaction->getNewValue());
$add = array_diff($new, $old);
$rem = array_diff($old, $new);
return array_merge($add, $rem);
}
public function getApplicationTransactionTitle(
PhabricatorApplicationTransaction $xaction) {
$author_phid = $xaction->getAuthorPHID();
$old = $this->decodeValue($xaction->getOldValue());
$new = $this->decodeValue($xaction->getNewValue());
$add = array_diff($new, $old);
$rem = array_diff($old, $new);
if ($add && !$rem) {
return pht(
'%s updated %s, added %d: %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName(),
phutil_count($add),
$xaction->renderHandleList($add));
} else if ($rem && !$add) {
return pht(
'%s updated %s, removed %s: %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName(),
phutil_count($rem),
$xaction->renderHandleList($rem));
} else {
return pht(
'%s updated %s, added %s: %s; removed %s: %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName(),
phutil_count($add),
$xaction->renderHandleList($add),
phutil_count($rem),
$xaction->renderHandleList($rem));
}
}
public function getApplicationTransactionTitleForFeed(
PhabricatorApplicationTransaction $xaction) {
$author_phid = $xaction->getAuthorPHID();
$object_phid = $xaction->getObjectPHID();
$old = $this->decodeValue($xaction->getOldValue());
$new = $this->decodeValue($xaction->getNewValue());
$add = array_diff($new, $old);
$rem = array_diff($old, $new);
if ($add && !$rem) {
return pht(
'%s updated %s for %s, added %d: %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName(),
$xaction->renderHandleLink($object_phid),
phutil_count($add),
$xaction->renderHandleList($add));
} else if ($rem && !$add) {
return pht(
'%s updated %s for %s, removed %s: %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName(),
$xaction->renderHandleLink($object_phid),
phutil_count($rem),
$xaction->renderHandleList($rem));
} else {
return pht(
'%s updated %s for %s, added %s: %s; removed %s: %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName(),
$xaction->renderHandleLink($object_phid),
phutil_count($add),
$xaction->renderHandleList($add),
phutil_count($rem),
$xaction->renderHandleList($rem));
}
}
public function validateApplicationTransactions(
PhabricatorApplicationTransactionEditor $editor,
$type,
array $xactions) {
$errors = parent::validateApplicationTransactions(
$editor,
$type,
$xactions);
// If the user is adding PHIDs, make sure the new PHIDs are valid and
// visible to the actor. It's OK for a user to edit a field which includes
// some invalid or restricted values, but they can't add new ones.
foreach ($xactions as $xaction) {
$old = $this->decodeValue($xaction->getOldValue());
$new = $this->decodeValue($xaction->getNewValue());
$add = array_diff($new, $old);
$invalid = PhabricatorObjectQuery::loadInvalidPHIDsForViewer(
$editor->getActor(),
$add);
if ($invalid) {
$error = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Invalid'),
pht(
'Some of the selected PHIDs in field "%s" are invalid or '.
'restricted: %s.',
$this->getFieldName(),
implode(', ', $invalid)),
$xaction);
$errors[] = $error;
$this->setFieldError(pht('Invalid'));
}
}
return $errors;
}
public function shouldAppearInHerald() {
return true;
}
public function getHeraldFieldConditions() {
return array(
HeraldAdapter::CONDITION_INCLUDE_ALL,
HeraldAdapter::CONDITION_INCLUDE_ANY,
HeraldAdapter::CONDITION_INCLUDE_NONE,
HeraldAdapter::CONDITION_EXISTS,
HeraldAdapter::CONDITION_NOT_EXISTS,
);
}
public function getHeraldFieldStandardType() {
return HeraldField::STANDARD_PHID_NULLABLE;
}
public function getHeraldFieldValue() {
// If the field has a `null` value, make sure we hand an `array()` to
// Herald.
$value = parent::getHeraldFieldValue();
if ($value) {
return $value;
}
return array();
}
protected function decodeValue($value) {
if ($value === null) {
return array();
}
$value = json_decode($value);
if (!is_array($value)) {
$value = array();
}
return $value;
}
protected function getHTTPParameterType() {
return new AphrontPHIDListHTTPParameterType();
}
}
diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php
index 5957afe56a..12e0aa6c3d 100644
--- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php
+++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php
@@ -1,161 +1,161 @@
<?php
final class PhabricatorStandardCustomFieldSelect
extends PhabricatorStandardCustomField {
public function getFieldType() {
return 'select';
}
public function buildFieldIndexes() {
$indexes = array();
$value = $this->getFieldValue();
if (strlen($value)) {
$indexes[] = $this->newStringIndex($value);
}
return $indexes;
}
public function readApplicationSearchValueFromRequest(
PhabricatorApplicationSearchEngine $engine,
AphrontRequest $request) {
return $request->getArr($this->getFieldKey());
}
public function applyApplicationSearchConstraintToQuery(
PhabricatorApplicationSearchEngine $engine,
PhabricatorCursorPagedPolicyAwareQuery $query,
$value) {
if ($value) {
$query->withApplicationSearchContainsConstraint(
$this->newStringIndex(null),
$value);
}
}
public function appendToApplicationSearchForm(
PhabricatorApplicationSearchEngine $engine,
AphrontFormView $form,
$value) {
if (!is_array($value)) {
$value = array();
}
$value = array_fuse($value);
$control = id(new AphrontFormCheckboxControl())
->setLabel($this->getFieldName());
foreach ($this->getOptions() as $name => $option) {
$control->addCheckbox(
$this->getFieldKey().'[]',
$name,
$option,
isset($value[$name]));
}
$form->appendChild($control);
}
public function getOptions() {
return $this->getFieldConfigValue('options', array());
}
public function renderEditControl(array $handles) {
return id(new AphrontFormSelectControl())
->setLabel($this->getFieldName())
->setCaption($this->getCaption())
->setName($this->getFieldKey())
->setValue($this->getFieldValue())
->setOptions($this->getOptions());
}
public function renderPropertyViewValue(array $handles) {
- if (!strlen($this->getFieldValue())) {
+ if (!phutil_nonempty_string($this->getFieldValue())) {
return null;
}
return idx($this->getOptions(), $this->getFieldValue());
}
public function getApplicationTransactionTitle(
PhabricatorApplicationTransaction $xaction) {
$author_phid = $xaction->getAuthorPHID();
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();
$old = idx($this->getOptions(), $old, $old);
$new = idx($this->getOptions(), $new, $new);
if (!$old) {
return pht(
'%s set %s to %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName(),
$new);
} else if (!$new) {
return pht(
'%s removed %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName());
} else {
return pht(
'%s changed %s from %s to %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName(),
$old,
$new);
}
}
public function shouldAppearInHerald() {
return true;
}
public function getHeraldFieldConditions() {
return array(
HeraldAdapter::CONDITION_IS_ANY,
HeraldAdapter::CONDITION_IS_NOT_ANY,
);
}
public function getHeraldFieldValueType($condition) {
$parameters = array(
'object' => get_class($this->getObject()),
'role' => PhabricatorCustomField::ROLE_HERALD,
'key' => $this->getFieldKey(),
);
$datasource = id(new PhabricatorStandardSelectCustomFieldDatasource())
->setParameters($parameters);
return id(new HeraldTokenizerFieldValue())
->setKey('custom.'.$this->getFieldKey())
->setDatasource($datasource)
->setValueMap($this->getOptions());
}
protected function getHTTPParameterType() {
return new AphrontSelectHTTPParameterType();
}
protected function newConduitSearchParameterType() {
return new ConduitStringListParameterType();
}
protected function newConduitEditParameterType() {
return new ConduitStringParameterType();
}
protected function newBulkParameterType() {
return id(new BulkSelectParameterType())
->setOptions($this->getOptions());
}
protected function newExportFieldType() {
return id(new PhabricatorOptionExportField())
->setOptions($this->getOptions());
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 17:42 (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1127081
Default Alt Text
(12 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment