@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorAuthContactNumberPrimaryTransaction
4 extends PhabricatorAuthContactNumberTransactionType {
5
6 const TRANSACTIONTYPE = 'primary';
7
8 public function generateOldValue($object) {
9 return (bool)$object->getIsPrimary();
10 }
11
12 public function applyInternalEffects($object, $value) {
13 $object->setIsPrimary((int)$value);
14 }
15
16 public function getTitle() {
17 return pht(
18 '%s made this the primary contact number.',
19 $this->renderAuthor());
20 }
21
22 public function validateTransactions($object, array $xactions) {
23 $errors = array();
24
25 foreach ($xactions as $xaction) {
26 $new_value = $xaction->getNewValue();
27
28 if (!$new_value) {
29 $errors[] = $this->newInvalidError(
30 pht(
31 'To choose a different primary contact number, make that '.
32 'number primary (instead of trying to demote this one).'),
33 $xaction);
34 continue;
35 }
36
37 if ($object->isDisabled()) {
38 $errors[] = $this->newInvalidError(
39 pht(
40 'You can not make a disabled number a primary contact number.'),
41 $xaction);
42 continue;
43 }
44
45 $mfa_error = $this->newContactNumberMFAError($object, $xaction);
46 if ($mfa_error) {
47 $errors[] = $mfa_error;
48 continue;
49 }
50 }
51
52 return $errors;
53 }
54
55}