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
) {
24 protected function assertValidRuleRecordFormat($value) {
25 if (!is_array($value)) {
28 'Owner rule value should be a list, but is not (value is "%s").',
29 phutil_describe_type($value)));
33 protected function assertValidRuleRecordValue($value) {
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) {
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))
57 'User PHID ("%s") is not a valid user.',
63 protected function newDropTransactions($object, $value) {
64 $value = $this->convertTokenizerValueToOwner($value);
66 $this->newTransaction()
67 ->setTransactionType(ManiphestTaskOwnerTransaction
::TRANSACTIONTYPE
)
68 ->setNewValue($value),
72 protected function newDropEffects($value) {
73 $owner_value = $this->convertTokenizerValueToOwner($value);
78 ->setContent($this->getRuleViewDescription($value))
79 ->addCondition('owner', '!=', $owner_value),
83 protected function getDefaultValue() {
87 protected function getPHUIXControlType() {
91 private function getDatasource() {
92 $datasource = id(new ManiphestAssigneeDatasource())
95 if ($this->getViewer()) {
96 $datasource->setViewer($this->getViewer());
102 protected function getPHUIXControlSpecification() {
103 $template = id(new AphrontTokenizerTemplateView())
104 ->setViewer($this->getViewer());
106 $template_markup = $template->render();
107 $datasource = $this->getDatasource();
110 'markup' => (string)hsprintf('%s', $template_markup),
112 'src' => $datasource->getDatasourceURI(),
113 'browseURI' => $datasource->getBrowseURI(),
114 'placeholder' => $datasource->getPlaceholderText(),
115 'limit' => $datasource->getLimit(),
121 public function getRuleViewLabel() {
122 return pht('Change Owner');
125 public function getRuleViewDescription($value) {
126 $value = $this->convertTokenizerValueToOwner($value);
129 return pht('Unassign task.');
132 'Assign task to %s.',
137 ->renderHandle($value)
142 public function getRuleViewIcon($value) {
143 return id(new PHUIIconView())
144 ->setIcon('fa-user', 'green');