1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-23 21:18:19 +01:00
phorge-phorge/src/applications/project/searchfield/PhabricatorProjectSearchField.php
epriestley 07f1a03262 Fix a bad call when prefilling ApplicationSearch from ?projects=some_slug
Summary: Fixes T10299.

Test Plan:
  - Visited `/maniphest/?projects=x` locally, where `x` is some valid project slug.
  - Before patch: Fatal on `requireViewer()` call.
  - After patch: Works correctly, filling the correct project into parameters.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10299

Differential Revision: https://secure.phabricator.com/D15214
2016-02-08 10:44:33 -08:00

54 lines
1.3 KiB
PHP

<?php
final class PhabricatorProjectSearchField
extends PhabricatorSearchTokenizerField {
protected function getDefaultValue() {
return array();
}
protected function newDatasource() {
return new PhabricatorProjectLogicalDatasource();
}
protected function getValueFromRequest(AphrontRequest $request, $key) {
$list = $this->getListFromRequest($request, $key);
$phids = array();
$slugs = array();
$project_type = PhabricatorProjectProjectPHIDType::TYPECONST;
foreach ($list as $item) {
$type = phid_get_type($item);
if ($type == $project_type) {
$phids[] = $item;
} else {
if (PhabricatorTypeaheadDatasource::isFunctionToken($item)) {
// If this is a function, pass it through unchanged; we'll evaluate
// it later.
$phids[] = $item;
} else {
$slugs[] = $item;
}
}
}
if ($slugs) {
$projects = id(new PhabricatorProjectQuery())
->setViewer($this->getViewer())
->withSlugs($slugs)
->execute();
foreach ($projects as $project) {
$phids[] = $project->getPHID();
}
$phids = array_unique($phids);
}
return $phids;
}
protected function newConduitParameterType() {
return new ConduitProjectListParameterType();
}
}