Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/typeahead/PhabricatorViewerDatasource.php
- This file was added.
<?php | |||||
final class PhabricatorViewerDatasource | |||||
extends PhabricatorTypeaheadDatasource { | |||||
public function getPlaceholderText() { | |||||
return pht('Type viewer()...'); | |||||
} | |||||
public function getDatasourceApplicationClass() { | |||||
return 'PhabricatorPeopleApplication'; | |||||
} | |||||
public function loadResults() { | |||||
if ($this->getViewer()->getPHID()) { | |||||
$results = array($this->renderViewerFunctionToken()); | |||||
} else { | |||||
$results = array(); | |||||
} | |||||
return $this->filterResultsAgainstTokens($results); | |||||
} | |||||
protected function canEvaluateFunction($function) { | |||||
if (!$this->getViewer()->getPHID()) { | |||||
return false; | |||||
} | |||||
return ($function == 'viewer'); | |||||
} | |||||
protected function evaluateFunction($function, array $argv_list) { | |||||
$results = array(); | |||||
foreach ($argv_list as $argv) { | |||||
$results[] = $this->getViewer()->getPHID(); | |||||
} | |||||
return $results; | |||||
} | |||||
public function renderFunctionTokens($function, array $argv_list) { | |||||
$tokens = array(); | |||||
foreach ($argv_list as $argv) { | |||||
$tokens[] = PhabricatorTypeaheadTokenView::newFromTypeaheadResult( | |||||
$this->renderViewerFunctionToken()); | |||||
} | |||||
return $tokens; | |||||
} | |||||
private function renderViewerFunctionToken() { | |||||
return $this->newFunctionResult() | |||||
->setName(pht('Current Viewer')) | |||||
->setPHID('viewer()') | |||||
->setUnique(true); | |||||
} | |||||
} |