Differential D7486 Diff 16907 src/applications/differential/landing/DifferntialLandingActionMenuEventListener.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/landing/DifferntialLandingActionMenuEventListener.php
- This file was added.
<?php | |||||
final class DifferntialLandingActionMenuEventListener | |||||
extends PhabricatorEventListener { | |||||
public function register() { | |||||
$this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS); | |||||
} | |||||
public function handleEvent(PhutilEvent $event) { | |||||
switch ($event->getType()) { | |||||
case PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS: | |||||
$this->handleActionsEvent($event); | |||||
break; | |||||
} | |||||
} | |||||
private function handleActionsEvent(PhutilEvent $event) { | |||||
$object = $event->getValue('object'); | |||||
$actions = null; | |||||
if ($object instanceof DifferentialRevision) { | |||||
$actions = $this->renderRevisionAction($event); | |||||
} | |||||
$this->addActionMenuItems($event, $actions); | |||||
} | |||||
private function renderRevisionAction(PhutilEvent $event) { | |||||
if (!$this->canUseApplication($event->getUser())) { | |||||
return null; | |||||
} | |||||
$revision = $event->getValue('object'); | |||||
$repository = $revision->getRepository(); | |||||
if ($repository === null) { | |||||
return null; | |||||
} | |||||
$strategies = id(new PhutilSymbolLoader()) | |||||
->setAncestorClass('DifferentialLandingStrategy') | |||||
->loadObjects(); | |||||
foreach ($strategies as $strategy) { | |||||
$actions = $strategy->createMenuItems( | |||||
$event->getUser(), | |||||
$revision, | |||||
$repository); | |||||
avivey: It felt safer to not provide the `$view` or `$event` to the strategy, and limiting it to… | |||||
epriestleyUnsubmitted Not Done Inline ActionsYeah, this seems reasonable to me. epriestley: Yeah, this seems reasonable to me. | |||||
$this->addActionMenuItems($event, $actions); | |||||
} | |||||
} | |||||
} | |||||
It felt safer to not provide the $view or $event to the strategy, and limiting it to providing the menu items.