2015-07-16 14:12:44 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class HeraldTokenizerFieldValue
|
|
|
|
extends HeraldFieldValue {
|
|
|
|
|
|
|
|
private $key;
|
|
|
|
private $datasource;
|
2015-07-16 14:12:54 -07:00
|
|
|
private $valueMap;
|
2015-07-16 14:12:44 -07:00
|
|
|
|
|
|
|
public function setKey($key) {
|
|
|
|
$this->key = $key;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getKey() {
|
|
|
|
return $this->key;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDatasource(PhabricatorTypeaheadDatasource $datasource) {
|
|
|
|
$this->datasource = $datasource;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDatasource() {
|
|
|
|
return $this->datasource;
|
|
|
|
}
|
|
|
|
|
2015-07-16 14:12:54 -07:00
|
|
|
public function setValueMap(array $value_map) {
|
|
|
|
$this->valueMap = $value_map;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getValueMap() {
|
|
|
|
return $this->valueMap;
|
|
|
|
}
|
|
|
|
|
2015-07-16 14:12:44 -07:00
|
|
|
public function getFieldValueKey() {
|
|
|
|
if ($this->getKey() === null) {
|
|
|
|
throw new PhutilInvalidStateException('setKey');
|
|
|
|
}
|
|
|
|
return 'tokenizer.'.$this->getKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getControlType() {
|
|
|
|
return self::CONTROL_TOKENIZER;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getControlTemplate() {
|
|
|
|
if ($this->getDatasource() === null) {
|
|
|
|
throw new PhutilInvalidStateException('setDatasource');
|
|
|
|
}
|
|
|
|
|
|
|
|
$datasource = $this->getDatasource();
|
|
|
|
$datasource->setViewer($this->getViewer());
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'tokenizer' => array(
|
|
|
|
'datasourceURI' => $datasource->getDatasourceURI(),
|
|
|
|
'browseURI' => $datasource->getBrowseURI(),
|
|
|
|
'placeholder' => $datasource->getPlaceholderText(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderFieldValue($value) {
|
|
|
|
$viewer = $this->getViewer();
|
2015-07-16 14:12:54 -07:00
|
|
|
$value = (array)$value;
|
|
|
|
|
|
|
|
if ($this->valueMap !== null) {
|
|
|
|
foreach ($value as $k => $v) {
|
|
|
|
$value[$k] = idx($this->valueMap, $v, $v);
|
|
|
|
}
|
|
|
|
return implode(', ', $value);
|
|
|
|
}
|
|
|
|
|
2015-07-16 14:12:44 -07:00
|
|
|
return $viewer->renderHandleList((array)$value)->setAsInline(true);
|
|
|
|
}
|
|
|
|
|
2015-07-16 14:12:54 -07:00
|
|
|
public function renderEditorValue($value) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$value = (array)$value;
|
|
|
|
|
2015-12-05 11:09:05 -08:00
|
|
|
$datasource = $this->getDatasource()
|
|
|
|
->setViewer($viewer);
|
2015-07-16 14:12:54 -07:00
|
|
|
|
2015-12-05 11:09:05 -08:00
|
|
|
return $datasource->getWireTokens($value);
|
2015-07-16 14:12:54 -07:00
|
|
|
}
|
|
|
|
|
2015-07-16 14:12:44 -07:00
|
|
|
}
|