@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

Inlines for custom herald actions

Summary: Ref D8784. Didn't see all of the inlines before hitting `arc land`. This fixes up the issues raised (and makes all the code nicer).

Test Plan: Made sure custom actions only appear for appropriate adapters and checked to ensure that they triggered correctly.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: edutibau, ite-klass, epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9796

+35 -28
+35 -28
src/applications/herald/adapter/HeraldAdapter.php
··· 106 106 107 107 public function getCustomActions() { 108 108 if ($this->customActions === null) { 109 - $this->customActions = id(new PhutilSymbolLoader()) 109 + $custom_actions = id(new PhutilSymbolLoader()) 110 110 ->setAncestorClass('HeraldCustomAction') 111 111 ->loadObjects(); 112 112 113 - foreach ($this->customActions as $key => $object) { 113 + foreach ($custom_actions as $key => $object) { 114 114 if (!$object->appliesToAdapter($this)) { 115 - unset($this->customActions[$key]); 115 + unset($custom_actions[$key]); 116 + } 117 + } 118 + 119 + $this->customActions = array(); 120 + foreach ($custom_actions as $action) { 121 + $key = $action->getActionKey(); 122 + 123 + if (array_key_exists($key, $this->customActions)) { 124 + throw new Exception( 125 + 'More than one Herald custom action implementation '. 126 + 'handles the action key: \''.$key.'\'.'); 116 127 } 128 + 129 + $this->customActions[$key] = $action; 117 130 } 118 131 } 119 132 ··· 163 176 } 164 177 } 165 178 166 - public abstract function applyHeraldEffects(array $effects); 179 + abstract public function applyHeraldEffects(array $effects); 167 180 168 181 protected function handleCustomHeraldEffect(HeraldEffect $effect) { 169 - foreach ($this->getCustomActions() as $custom_action) { 170 - if ($effect->getAction() == $custom_action->getActionKey()) { 171 - $result = $custom_action->applyEffect( 172 - $this, 173 - $this->getObject(), 174 - $effect); 182 + $custom_action = idx($this->getCustomActions(), $effect->getAction()); 175 183 176 - if ($result !== null) { 177 - return $result; 178 - } 179 - } 184 + if ($custom_action !== null) { 185 + return $custom_action->applyEffect( 186 + $this, 187 + $this->getObject(), 188 + $effect); 180 189 } 181 190 182 191 return null; ··· 688 697 689 698 /* -( Actions )------------------------------------------------------------ */ 690 699 691 - public function getActions($rule_type) { 700 + public function getCustomActionsForRuleType($rule_type) { 692 701 $results = array(); 693 702 foreach ($this->getCustomActions() as $custom_action) { 694 703 if ($custom_action->appliesToRuleType($rule_type)) { 695 - $results[] = $custom_action->getActionKey(); 704 + $results[] = $custom_action; 696 705 } 697 706 } 698 707 return $results; 708 + } 709 + 710 + public function getActions($rule_type) { 711 + $custom_actions = $this->getCustomActionsForRuleType($rule_type); 712 + return mpull($custom_actions, 'getActionKey'); 699 713 } 700 714 701 715 public function getActionNameMap($rule_type) { ··· 737 751 throw new Exception("Unknown rule type '{$rule_type}'!"); 738 752 } 739 753 740 - foreach ($this->getCustomActions() as $custom_action) { 741 - if ($custom_action->appliesToRuleType($rule_type)) { 742 - $standard[$custom_action->getActionKey()] = 743 - $custom_action->getActionName(); 744 - } 745 - } 754 + $custom_actions = $this->getCustomActionsForRuleType($rule_type); 755 + $standard += mpull($custom_actions, 'getActionName', 'getActionKey'); 746 756 747 757 return $standard; 748 758 } ··· 922 932 } 923 933 } 924 934 925 - foreach ($this->getCustomActions() as $custom_action) { 926 - if ($custom_action->appliesToRuleType($rule_type)) { 927 - if ($action === $custom_action->getActionKey()) { 928 - return $custom_action->getActionType(); 929 - } 930 - } 935 + $custom_action = idx($this->getCustomActions(), $action); 936 + if ($custom_action !== null) { 937 + return $custom_action->getActionType(); 931 938 } 932 939 933 940 throw new Exception("Unknown or invalid action '".$action."'.");