Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / project / trigger / PhabricatorProjectTriggerManiphestOwnerRule.php
blob1648f1bc8b861ccd84be4bab4ade57aed9b0492f
1 <?php
3 final class PhabricatorProjectTriggerManiphestOwnerRule
4 extends PhabricatorProjectTriggerRule {
6 const TRIGGERTYPE = 'task.owner';
8 public function getSelectControlName() {
9 return pht('Assign task to');
12 protected function getValueForEditorField() {
13 return $this->getDatasource()->getWireTokens($this->getValue());
16 private function convertTokenizerValueToOwner($value) {
17 $value = head($value);
18 if ($value === PhabricatorPeopleNoOwnerDatasource::FUNCTION_TOKEN) {
19 $value = null;
21 return $value;
24 protected function assertValidRuleRecordFormat($value) {
25 if (!is_array($value)) {
26 throw new Exception(
27 pht(
28 'Owner rule value should be a list, but is not (value is "%s").',
29 phutil_describe_type($value)));
33 protected function assertValidRuleRecordValue($value) {
34 if (!$value) {
35 throw new Exception(
36 pht(
37 'Owner rule value is required. Specify a user to assign tasks '.
38 'to, or the token "none()" to unassign tasks.'));
41 if (count($value) > 1) {
42 throw new Exception(
43 pht(
44 'Owner rule value must have only one elmement (value is "%s").',
45 implode(', ', $value)));
48 $owner_phid = $this->convertTokenizerValueToOwner($value);
49 if ($owner_phid !== null) {
50 $user = id(new PhabricatorPeopleQuery())
51 ->setViewer($this->getViewer())
52 ->withPHIDs(array($owner_phid))
53 ->executeOne();
54 if (!$user) {
55 throw new Exception(
56 pht(
57 'User PHID ("%s") is not a valid user.',
58 $owner_phid));
63 protected function newDropTransactions($object, $value) {
64 $value = $this->convertTokenizerValueToOwner($value);
65 return array(
66 $this->newTransaction()
67 ->setTransactionType(ManiphestTaskOwnerTransaction::TRANSACTIONTYPE)
68 ->setNewValue($value),
72 protected function newDropEffects($value) {
73 $owner_value = $this->convertTokenizerValueToOwner($value);
75 return array(
76 $this->newEffect()
77 ->setIcon('fa-user')
78 ->setContent($this->getRuleViewDescription($value))
79 ->addCondition('owner', '!=', $owner_value),
83 protected function getDefaultValue() {
84 return null;
87 protected function getPHUIXControlType() {
88 return 'tokenizer';
91 private function getDatasource() {
92 $datasource = id(new ManiphestAssigneeDatasource())
93 ->setLimit(1);
95 if ($this->getViewer()) {
96 $datasource->setViewer($this->getViewer());
99 return $datasource;
102 protected function getPHUIXControlSpecification() {
103 $template = id(new AphrontTokenizerTemplateView())
104 ->setViewer($this->getViewer());
106 $template_markup = $template->render();
107 $datasource = $this->getDatasource();
109 return array(
110 'markup' => (string)hsprintf('%s', $template_markup),
111 'config' => array(
112 'src' => $datasource->getDatasourceURI(),
113 'browseURI' => $datasource->getBrowseURI(),
114 'placeholder' => $datasource->getPlaceholderText(),
115 'limit' => $datasource->getLimit(),
117 'value' => null,
121 public function getRuleViewLabel() {
122 return pht('Change Owner');
125 public function getRuleViewDescription($value) {
126 $value = $this->convertTokenizerValueToOwner($value);
128 if (!$value) {
129 return pht('Unassign task.');
130 } else {
131 return pht(
132 'Assign task to %s.',
133 phutil_tag(
134 'strong',
135 array(),
136 $this->getViewer()
137 ->renderHandle($value)
138 ->render()));
142 public function getRuleViewIcon($value) {
143 return id(new PHUIIconView())
144 ->setIcon('fa-user', 'green');