Differential D17235 Diff 41452 src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php
<?php | <?php | ||||
final class PhabricatorDashboardProfileMenuItem | final class PhabricatorDashboardProfileMenuItem | ||||
extends PhabricatorProfileMenuItem { | extends PhabricatorProfileMenuItem { | ||||
const MENUITEMKEY = 'dashboard'; | const MENUITEMKEY = 'dashboard'; | ||||
const FIELD_DASHBOARD = 'dashboardPHID'; | |||||
private $dashboard; | private $dashboard; | ||||
public function getMenuItemTypeIcon() { | public function getMenuItemTypeIcon() { | ||||
return 'fa-dashboard'; | return 'fa-dashboard'; | ||||
} | } | ||||
public function getMenuItemTypeName() { | public function getMenuItemTypeName() { | ||||
return pht('Dashboard'); | return pht('Dashboard'); | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | final class PhabricatorDashboardProfileMenuItem | ||||
public function buildEditEngineFields( | public function buildEditEngineFields( | ||||
PhabricatorProfileMenuItemConfiguration $config) { | PhabricatorProfileMenuItemConfiguration $config) { | ||||
return array( | return array( | ||||
id(new PhabricatorTextEditField()) | id(new PhabricatorTextEditField()) | ||||
->setKey('name') | ->setKey('name') | ||||
->setLabel(pht('Name')) | ->setLabel(pht('Name')) | ||||
->setValue($this->getName($config)), | ->setValue($this->getName($config)), | ||||
id(new PhabricatorDatasourceEditField()) | id(new PhabricatorDatasourceEditField()) | ||||
->setKey('dashboardPHID') | ->setKey(self::FIELD_DASHBOARD) | ||||
->setLabel(pht('Dashboard')) | ->setLabel(pht('Dashboard')) | ||||
->setIsRequired(true) | ->setIsRequired(true) | ||||
->setDatasource(new PhabricatorDashboardDatasource()) | ->setDatasource(new PhabricatorDashboardDatasource()) | ||||
->setSingleValue($config->getMenuItemProperty('dashboardPHID')), | ->setSingleValue($config->getMenuItemProperty('dashboardPHID')), | ||||
); | ); | ||||
} | } | ||||
private function getName( | private function getName( | ||||
Show All 18 Lines | $item = $this->newItem() | ||||
->setName($name) | ->setName($name) | ||||
->setIcon($icon); | ->setIcon($icon); | ||||
return array( | return array( | ||||
$item, | $item, | ||||
); | ); | ||||
} | } | ||||
public function validateTransactions( | |||||
PhabricatorProfileMenuItemConfiguration $config, | |||||
$field_key, | |||||
$value, | |||||
array $xactions) { | |||||
$viewer = $this->getViewer(); | |||||
$errors = array(); | |||||
if ($field_key == self::FIELD_DASHBOARD) { | |||||
if ($this->isEmptyTransaction($value, $xactions)) { | |||||
$errors[] = $this->newRequiredError( | |||||
pht('You must choose a dashboard.'), | |||||
$field_key); | |||||
} | |||||
foreach ($xactions as $xaction) { | |||||
$new = $xaction['new']; | |||||
if (!$new) { | |||||
continue; | |||||
} | |||||
if ($new === $value) { | |||||
continue; | |||||
} | |||||
$dashboards = id(new PhabricatorDashboardQuery()) | |||||
->setViewer($viewer) | |||||
->withPHIDs(array($new)) | |||||
->execute(); | |||||
if (!$dashboards) { | |||||
$errors[] = $this->newInvalidError( | |||||
pht( | |||||
'Dashboard "%s" is not a valid dashboard which you have '. | |||||
'permission to see.', | |||||
$new), | |||||
$xaction['xaction']); | |||||
} | |||||
} | |||||
} | |||||
return $errors; | |||||
} | |||||
} | } |