Differential D17235 Diff 41452 src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php
<?php | <?php | ||||
final class PhabricatorProjectProfileMenuItem | final class PhabricatorProjectProfileMenuItem | ||||
extends PhabricatorProfileMenuItem { | extends PhabricatorProfileMenuItem { | ||||
const MENUITEMKEY = 'project'; | const MENUITEMKEY = 'project'; | ||||
const FIELD_PROJECT = 'project'; | |||||
private $project; | private $project; | ||||
public function getMenuItemTypeIcon() { | public function getMenuItemTypeIcon() { | ||||
return 'fa-briefcase'; | return 'fa-briefcase'; | ||||
} | } | ||||
public function getMenuItemTypeName() { | public function getMenuItemTypeName() { | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | final class PhabricatorProjectProfileMenuItem | ||||
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('project') | ->setKey(self::FIELD_PROJECT) | ||||
->setLabel(pht('Project')) | ->setLabel(pht('Project')) | ||||
->setIsRequired(true) | ->setIsRequired(true) | ||||
->setDatasource(new PhabricatorProjectDatasource()) | ->setDatasource(new PhabricatorProjectDatasource()) | ||||
->setSingleValue($config->getMenuItemProperty('project')), | ->setSingleValue($config->getMenuItemProperty('project')), | ||||
); | ); | ||||
} | } | ||||
private function getName( | private function getName( | ||||
Show All 18 Lines | $item = $this->newItem() | ||||
->setName($name) | ->setName($name) | ||||
->setProfileImage($picture); | ->setProfileImage($picture); | ||||
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_PROJECT) { | |||||
if ($this->isEmptyTransaction($value, $xactions)) { | |||||
$errors[] = $this->newRequiredError( | |||||
pht('You must choose a project.'), | |||||
$field_key); | |||||
} | |||||
foreach ($xactions as $xaction) { | |||||
$new = $xaction['new']; | |||||
if (!$new) { | |||||
continue; | |||||
} | |||||
if ($new === $value) { | |||||
continue; | |||||
} | |||||
$projects = id(new PhabricatorProjectQuery()) | |||||
->setViewer($viewer) | |||||
->withPHIDs(array($new)) | |||||
->execute(); | |||||
if (!$projects) { | |||||
$errors[] = $this->newInvalidError( | |||||
pht( | |||||
'Project "%s" is not a valid project which you have '. | |||||
'permission to see.', | |||||
$new), | |||||
$xaction['xaction']); | |||||
} | |||||
} | |||||
} | |||||
return $errors; | |||||
} | |||||
} | } |