protected function buildCustomEditFields($object)
 {
     $status_map = $this->getTaskStatusMap($object);
     $priority_map = $this->getTaskPriorityMap($object);
     if ($object->isClosed()) {
         $default_status = ManiphestTaskStatus::getDefaultStatus();
     } else {
         $default_status = ManiphestTaskStatus::getDefaultClosedStatus();
     }
     if ($object->getOwnerPHID()) {
         $owner_value = array($object->getOwnerPHID());
     } else {
         $owner_value = array($this->getViewer()->getPHID());
     }
     return array(id(new PhabricatorHandlesEditField())->setKey('parent')->setLabel(pht('Parent Task'))->setDescription(pht('Task to make this a subtask of.'))->setConduitDescription(pht('Create as a subtask of another task.'))->setConduitTypeDescription(pht('PHID of the parent task.'))->setAliases(array('parentPHID'))->setTransactionType(ManiphestTransaction::TYPE_PARENT)->setHandleParameterType(new ManiphestTaskListHTTPParameterType())->setSingleValue(null)->setIsReorderable(false)->setIsDefaultable(false)->setIsLockable(false), id(new PhabricatorHandlesEditField())->setKey('column')->setLabel(pht('Column'))->setDescription(pht('Workboard column to create this task into.'))->setConduitDescription(pht('Create into a workboard column.'))->setConduitTypeDescription(pht('PHID of workboard column.'))->setAliases(array('columnPHID'))->setTransactionType(ManiphestTransaction::TYPE_COLUMN)->setSingleValue(null)->setIsInvisible(true)->setIsReorderable(false)->setIsDefaultable(false)->setIsLockable(false), id(new PhabricatorTextEditField())->setKey('title')->setLabel(pht('Title'))->setDescription(pht('Name of the task.'))->setConduitDescription(pht('Rename the task.'))->setConduitTypeDescription(pht('New task name.'))->setTransactionType(ManiphestTransaction::TYPE_TITLE)->setIsRequired(true)->setValue($object->getTitle()), id(new PhabricatorUsersEditField())->setKey('owner')->setAliases(array('ownerPHID', 'assign', 'assigned'))->setLabel(pht('Assigned To'))->setDescription(pht('User who is responsible for the task.'))->setConduitDescription(pht('Reassign the task.'))->setConduitTypeDescription(pht('New task owner, or `null` to unassign.'))->setTransactionType(ManiphestTransaction::TYPE_OWNER)->setIsCopyable(true)->setSingleValue($object->getOwnerPHID())->setCommentActionLabel(pht('Assign / Claim'))->setCommentActionValue($owner_value), id(new PhabricatorSelectEditField())->setKey('status')->setLabel(pht('Status'))->setDescription(pht('Status of the task.'))->setConduitDescription(pht('Change the task status.'))->setConduitTypeDescription(pht('New task status constant.'))->setTransactionType(ManiphestTransaction::TYPE_STATUS)->setIsCopyable(true)->setValue($object->getStatus())->setOptions($status_map)->setCommentActionLabel(pht('Change Status'))->setCommentActionValue($default_status), id(new PhabricatorSelectEditField())->setKey('priority')->setLabel(pht('Priority'))->setDescription(pht('Priority of the task.'))->setConduitDescription(pht('Change the priority of the task.'))->setConduitTypeDescription(pht('New task priority constant.'))->setTransactionType(ManiphestTransaction::TYPE_PRIORITY)->setIsCopyable(true)->setValue($object->getPriority())->setOptions($priority_map)->setCommentActionLabel(pht('Change Priority')), id(new PhabricatorRemarkupEditField())->setKey('description')->setLabel(pht('Description'))->setDescription(pht('Task description.'))->setConduitDescription(pht('Update the task description.'))->setConduitTypeDescription(pht('New task description.'))->setTransactionType(ManiphestTransaction::TYPE_DESCRIPTION)->setValue($object->getDescription())->setPreviewPanel(id(new PHUIRemarkupPreviewPanel())->setHeader(pht('Description Preview'))));
 }
 protected function buildCustomEditFields($object)
 {
     $status_map = $this->getTaskStatusMap($object);
     $priority_map = $this->getTaskPriorityMap($object);
     if ($object->isClosed()) {
         $priority_label = null;
         $owner_label = null;
         $default_status = ManiphestTaskStatus::getDefaultStatus();
     } else {
         $priority_label = pht('Change Priority');
         $owner_label = pht('Assign / Claim');
         $default_status = ManiphestTaskStatus::getDefaultClosedStatus();
     }
     if ($object->getOwnerPHID()) {
         $owner_value = array($object->getOwnerPHID());
     } else {
         $owner_value = array($this->getViewer()->getPHID());
     }
     return array(id(new PhabricatorTextEditField())->setKey('title')->setLabel(pht('Title'))->setDescription(pht('Name of the task.'))->setTransactionType(ManiphestTransaction::TYPE_TITLE)->setIsRequired(true)->setValue($object->getTitle()), id(new PhabricatorSelectEditField())->setKey('status')->setLabel(pht('Status'))->setDescription(pht('Status of the task.'))->setTransactionType(ManiphestTransaction::TYPE_STATUS)->setValue($object->getStatus())->setOptions($status_map)->setCommentActionLabel(pht('Change Status'))->setCommentActionDefaultValue($default_status), id(new PhabricatorUsersEditField())->setKey('owner')->setAliases(array('ownerPHID', 'assign', 'assigned'))->setLabel(pht('Assigned To'))->setDescription(pht('User who is responsible for the task.'))->setTransactionType(ManiphestTransaction::TYPE_OWNER)->setSingleValue($object->getOwnerPHID())->setCommentActionLabel($owner_label)->setCommentActionDefaultValue($owner_value), id(new PhabricatorSelectEditField())->setKey('priority')->setLabel(pht('Priority'))->setDescription(pht('Priority of the task.'))->setTransactionType(ManiphestTransaction::TYPE_PRIORITY)->setValue($object->getPriority())->setOptions($priority_map)->setCommentActionLabel($priority_label), id(new PhabricatorRemarkupEditField())->setKey('description')->setLabel(pht('Description'))->setDescription(pht('Task description.'))->setTransactionType(ManiphestTransaction::TYPE_DESCRIPTION)->setValue($object->getDescription()));
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $results = array('defaultStatus' => ManiphestTaskStatus::getDefaultStatus(), 'defaultClosedStatus' => ManiphestTaskStatus::getDefaultClosedStatus(), 'duplicateStatus' => ManiphestTaskStatus::getDuplicateStatus(), 'openStatuses' => ManiphestTaskStatus::getOpenStatusConstants(), 'closedStatuses' => ManiphestTaskStatus::getClosedStatusConstants(), 'allStatuses' => array_keys(ManiphestTaskStatus::getTaskStatusMap()), 'statusMap' => ManiphestTaskStatus::getTaskStatusMap());
     return $results;
 }
 public function buildTransactions(PhabricatorUser $viewer, PhabricatorApplicationTransactionInterface $object, PhabricatorMetaMTAReceivedMail $mail, $command, array $argv)
 {
     $xactions = array();
     $xactions[] = $object->getApplicationTransactionTemplate()->setTransactionType(ManiphestTransaction::TYPE_STATUS)->setNewValue(ManiphestTaskStatus::getDefaultClosedStatus());
     return $xactions;
 }
    protected function buildCustomEditFields($object)
    {
        $status_map = $this->getTaskStatusMap($object);
        $priority_map = $this->getTaskPriorityMap($object);
        if ($object->isClosed()) {
            $default_status = ManiphestTaskStatus::getDefaultStatus();
        } else {
            $default_status = ManiphestTaskStatus::getDefaultClosedStatus();
        }
        if ($object->getOwnerPHID()) {
            $owner_value = array($object->getOwnerPHID());
        } else {
            $owner_value = array($this->getViewer()->getPHID());
        }
        $column_documentation = pht(<<<EODOCS
You can use this transaction type to create a task into a particular workboard
column, or move an existing task between columns.

The transaction value can be specified in several forms. Some are simpler but
less powerful, while others are more complex and more powerful.

The simplest valid value is a single column PHID:

```lang=json
"PHID-PCOL-1111"
```

This will move the task into that column, or create the task into that column
if you are creating a new task. If the task is currently on the board, it will
be moved out of any exclusive columns. If the task is not currently on the
board, it will be added to the board.

You can also perform multiple moves at the same time by passing a list of
PHIDs:

```lang=json
["PHID-PCOL-2222", "PHID-PCOL-3333"]
```

This is equivalent to performing each move individually.

The most complex and most powerful form uses a dictionary to provide additional
information about the move, including an optional specific position within the
column.

The target column should be identified as `columnPHID`, and you may select a
position by passing either `beforePHID` or `afterPHID`, specifying the PHID of
a task currently in the column that you want to move this task before or after:

```lang=json
[
  {
    "columnPHID": "PHID-PCOL-4444",
    "beforePHID": "PHID-TASK-5555"
  }
]
```

Note that this affects only the "natural" position of the task. The task
position when the board is sorted by some other attribute (like priority)
depends on that attribute value: change a task's priority to move it on
priority-sorted boards.
EODOCS
);
        $column_map = $this->getColumnMap($object);
        $fields = array(id(new PhabricatorHandlesEditField())->setKey('parent')->setLabel(pht('Parent Task'))->setDescription(pht('Task to make this a subtask of.'))->setConduitDescription(pht('Create as a subtask of another task.'))->setConduitTypeDescription(pht('PHID of the parent task.'))->setAliases(array('parentPHID'))->setTransactionType(ManiphestTransaction::TYPE_PARENT)->setHandleParameterType(new ManiphestTaskListHTTPParameterType())->setSingleValue(null)->setIsReorderable(false)->setIsDefaultable(false)->setIsLockable(false), id(new PhabricatorColumnsEditField())->setKey('column')->setLabel(pht('Column'))->setDescription(pht('Create a task in a workboard column.'))->setConduitDescription(pht('Move a task to one or more workboard columns.'))->setConduitTypeDescription(pht('List of columns to move the task to.'))->setConduitDocumentation($column_documentation)->setAliases(array('columnPHID', 'columns', 'columnPHIDs'))->setTransactionType(PhabricatorTransactions::TYPE_COLUMNS)->setIsReorderable(false)->setIsDefaultable(false)->setIsLockable(false)->setCommentActionLabel(pht('Move on Workboard'))->setCommentActionOrder(2000)->setColumnMap($column_map), id(new PhabricatorTextEditField())->setKey('title')->setLabel(pht('Title'))->setDescription(pht('Name of the task.'))->setConduitDescription(pht('Rename the task.'))->setConduitTypeDescription(pht('New task name.'))->setTransactionType(ManiphestTransaction::TYPE_TITLE)->setIsRequired(true)->setValue($object->getTitle()), id(new PhabricatorUsersEditField())->setKey('owner')->setAliases(array('ownerPHID', 'assign', 'assigned'))->setLabel(pht('Assigned To'))->setDescription(pht('User who is responsible for the task.'))->setConduitDescription(pht('Reassign the task.'))->setConduitTypeDescription(pht('New task owner, or `null` to unassign.'))->setTransactionType(ManiphestTransaction::TYPE_OWNER)->setIsCopyable(true)->setSingleValue($object->getOwnerPHID())->setCommentActionLabel(pht('Assign / Claim'))->setCommentActionValue($owner_value), id(new PhabricatorSelectEditField())->setKey('status')->setLabel(pht('Status'))->setDescription(pht('Status of the task.'))->setConduitDescription(pht('Change the task status.'))->setConduitTypeDescription(pht('New task status constant.'))->setTransactionType(ManiphestTransaction::TYPE_STATUS)->setIsCopyable(true)->setValue($object->getStatus())->setOptions($status_map)->setCommentActionLabel(pht('Change Status'))->setCommentActionValue($default_status), id(new PhabricatorSelectEditField())->setKey('priority')->setLabel(pht('Priority'))->setDescription(pht('Priority of the task.'))->setConduitDescription(pht('Change the priority of the task.'))->setConduitTypeDescription(pht('New task priority constant.'))->setTransactionType(ManiphestTransaction::TYPE_PRIORITY)->setIsCopyable(true)->setValue($object->getPriority())->setOptions($priority_map)->setCommentActionLabel(pht('Change Priority')));
        if (ManiphestTaskPoints::getIsEnabled()) {
            $points_label = ManiphestTaskPoints::getPointsLabel();
            $action_label = ManiphestTaskPoints::getPointsActionLabel();
            $fields[] = id(new PhabricatorPointsEditField())->setKey('points')->setLabel($points_label)->setDescription(pht('Point value of the task.'))->setConduitDescription(pht('Change the task point value.'))->setConduitTypeDescription(pht('New task point value.'))->setTransactionType(ManiphestTransaction::TYPE_POINTS)->setIsCopyable(true)->setValue($object->getPoints())->setCommentActionLabel($action_label);
        }
        $fields[] = id(new PhabricatorRemarkupEditField())->setKey('description')->setLabel(pht('Description'))->setDescription(pht('Task description.'))->setConduitDescription(pht('Update the task description.'))->setConduitTypeDescription(pht('New task description.'))->setTransactionType(ManiphestTransaction::TYPE_DESCRIPTION)->setValue($object->getDescription())->setPreviewPanel(id(new PHUIRemarkupPreviewPanel())->setHeader(pht('Description Preview')));
        return $fields;
    }
 protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail)
 {
     // NOTE: We'll drop in here on both the "reply to a task" and "create a
     // new task" workflows! Make sure you test both if you make changes!
     $task = $this->getMailReceiver();
     $is_new_task = !$task->getID();
     $user = $this->getActor();
     $body_data = $mail->parseBody();
     $body = $body_data['body'];
     $body = $this->enhanceBodyWithAttachments($body, $mail->getAttachments());
     $xactions = array();
     $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_EMAIL, array('id' => $mail->getID()));
     $template = new ManiphestTransaction();
     $is_unsub = false;
     if ($is_new_task) {
         $task = ManiphestTask::initializeNewTask($user);
         $xactions[] = id(new ManiphestTransaction())->setTransactionType(ManiphestTransaction::TYPE_STATUS)->setNewValue(ManiphestTaskStatus::getDefaultStatus());
         $xactions[] = id(new ManiphestTransaction())->setTransactionType(ManiphestTransaction::TYPE_TITLE)->setNewValue(nonempty($mail->getSubject(), pht('Untitled Task')));
         $xactions[] = id(new ManiphestTransaction())->setTransactionType(ManiphestTransaction::TYPE_DESCRIPTION)->setNewValue($body);
     } else {
         $command = $body_data['command'];
         $command_value = $body_data['command_value'];
         $ttype = PhabricatorTransactions::TYPE_COMMENT;
         $new_value = null;
         switch ($command) {
             case 'close':
                 $ttype = ManiphestTransaction::TYPE_STATUS;
                 $new_value = ManiphestTaskStatus::getDefaultClosedStatus();
                 break;
             case 'claim':
                 $ttype = ManiphestTransaction::TYPE_OWNER;
                 $new_value = $user->getPHID();
                 break;
             case 'assign':
                 $ttype = ManiphestTransaction::TYPE_OWNER;
                 if ($command_value) {
                     $assign_users = id(new PhabricatorPeopleQuery())->setViewer($user)->withUsernames(array($command_value))->execute();
                     if ($assign_users) {
                         $assign_user = head($assign_users);
                         $new_value = $assign_user->getPHID();
                     }
                 }
                 // assign to the user by default
                 if (!$new_value) {
                     $new_value = $user->getPHID();
                 }
                 break;
             case 'unsubscribe':
                 $is_unsub = true;
                 $ttype = ManiphestTransaction::TYPE_CCS;
                 $ccs = $task->getCCPHIDs();
                 foreach ($ccs as $k => $phid) {
                     if ($phid == $user->getPHID()) {
                         unset($ccs[$k]);
                     }
                 }
                 $new_value = array_values($ccs);
                 break;
         }
         if ($ttype != PhabricatorTransactions::TYPE_COMMENT) {
             $xaction = clone $template;
             $xaction->setTransactionType($ttype);
             $xaction->setNewValue($new_value);
             $xactions[] = $xaction;
         }
         if (strlen($body)) {
             $xaction = clone $template;
             $xaction->setTransactionType(PhabricatorTransactions::TYPE_COMMENT);
             $xaction->attachComment(id(new ManiphestTransactionComment())->setContent($body));
             $xactions[] = $xaction;
         }
     }
     $ccs = $mail->loadCCPHIDs();
     $old_ccs = $task->getCCPHIDs();
     $new_ccs = array_merge($old_ccs, $ccs);
     if (!$is_unsub) {
         $new_ccs[] = $user->getPHID();
     }
     $new_ccs = array_unique($new_ccs);
     if (array_diff($new_ccs, $old_ccs)) {
         $cc_xaction = clone $template;
         $cc_xaction->setTransactionType(ManiphestTransaction::TYPE_CCS);
         $cc_xaction->setNewValue($new_ccs);
         $xactions[] = $cc_xaction;
     }
     $event = new PhabricatorEvent(PhabricatorEventType::TYPE_MANIPHEST_WILLEDITTASK, array('task' => $task, 'mail' => $mail, 'new' => $is_new_task, 'transactions' => $xactions));
     $event->setUser($user);
     PhutilEventEngine::dispatchEvent($event);
     $task = $event->getValue('task');
     $xactions = $event->getValue('transactions');
     $editor = id(new ManiphestTransactionEditor())->setActor($user)->setParentMessageID($mail->getMessageID())->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs())->setContinueOnNoEffect(true)->setContinueOnMissingFields(true)->setContentSource($content_source)->applyTransactions($task, $xactions);
     $event = new PhabricatorEvent(PhabricatorEventType::TYPE_MANIPHEST_DIDEDITTASK, array('task' => $task, 'new' => $is_new_task, 'transactions' => $xactions));
     $event->setUser($user);
     PhutilEventEngine::dispatchEvent($event);
 }