Path: blob/master/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php
12242 views
<?php12final class PhabricatorStandardCustomFieldSelect3extends PhabricatorStandardCustomField {45public function getFieldType() {6return 'select';7}89public function buildFieldIndexes() {10$indexes = array();1112$value = $this->getFieldValue();13if (strlen($value)) {14$indexes[] = $this->newStringIndex($value);15}1617return $indexes;18}1920public function readApplicationSearchValueFromRequest(21PhabricatorApplicationSearchEngine $engine,22AphrontRequest $request) {23return $request->getArr($this->getFieldKey());24}2526public function applyApplicationSearchConstraintToQuery(27PhabricatorApplicationSearchEngine $engine,28PhabricatorCursorPagedPolicyAwareQuery $query,29$value) {30if ($value) {31$query->withApplicationSearchContainsConstraint(32$this->newStringIndex(null),33$value);34}35}3637public function appendToApplicationSearchForm(38PhabricatorApplicationSearchEngine $engine,39AphrontFormView $form,40$value) {4142if (!is_array($value)) {43$value = array();44}45$value = array_fuse($value);4647$control = id(new AphrontFormCheckboxControl())48->setLabel($this->getFieldName());4950foreach ($this->getOptions() as $name => $option) {51$control->addCheckbox(52$this->getFieldKey().'[]',53$name,54$option,55isset($value[$name]));56}5758$form->appendChild($control);59}6061public function getOptions() {62return $this->getFieldConfigValue('options', array());63}6465public function renderEditControl(array $handles) {66return id(new AphrontFormSelectControl())67->setLabel($this->getFieldName())68->setCaption($this->getCaption())69->setName($this->getFieldKey())70->setValue($this->getFieldValue())71->setOptions($this->getOptions());72}7374public function renderPropertyViewValue(array $handles) {75if (!strlen($this->getFieldValue())) {76return null;77}78return idx($this->getOptions(), $this->getFieldValue());79}8081public function getApplicationTransactionTitle(82PhabricatorApplicationTransaction $xaction) {83$author_phid = $xaction->getAuthorPHID();84$old = $xaction->getOldValue();85$new = $xaction->getNewValue();8687$old = idx($this->getOptions(), $old, $old);88$new = idx($this->getOptions(), $new, $new);8990if (!$old) {91return pht(92'%s set %s to %s.',93$xaction->renderHandleLink($author_phid),94$this->getFieldName(),95$new);96} else if (!$new) {97return pht(98'%s removed %s.',99$xaction->renderHandleLink($author_phid),100$this->getFieldName());101} else {102return pht(103'%s changed %s from %s to %s.',104$xaction->renderHandleLink($author_phid),105$this->getFieldName(),106$old,107$new);108}109}110111public function shouldAppearInHerald() {112return true;113}114115public function getHeraldFieldConditions() {116return array(117HeraldAdapter::CONDITION_IS_ANY,118HeraldAdapter::CONDITION_IS_NOT_ANY,119);120}121122public function getHeraldFieldValueType($condition) {123$parameters = array(124'object' => get_class($this->getObject()),125'role' => PhabricatorCustomField::ROLE_HERALD,126'key' => $this->getFieldKey(),127);128129$datasource = id(new PhabricatorStandardSelectCustomFieldDatasource())130->setParameters($parameters);131132return id(new HeraldTokenizerFieldValue())133->setKey('custom.'.$this->getFieldKey())134->setDatasource($datasource)135->setValueMap($this->getOptions());136}137138protected function getHTTPParameterType() {139return new AphrontSelectHTTPParameterType();140}141142protected function newConduitSearchParameterType() {143return new ConduitStringListParameterType();144}145146protected function newConduitEditParameterType() {147return new ConduitStringParameterType();148}149150protected function newBulkParameterType() {151return id(new BulkSelectParameterType())152->setOptions($this->getOptions());153}154155protected function newExportFieldType() {156return id(new PhabricatorOptionExportField())157->setOptions($this->getOptions());158}159160}161162163