Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/menuitem/PhabricatorLinkProfileMenuItem.php
<?php | <?php | ||||
final class PhabricatorLinkProfileMenuItem | final class PhabricatorLinkProfileMenuItem | ||||
extends PhabricatorProfileMenuItem { | extends PhabricatorProfileMenuItem { | ||||
const MENUITEMKEY = 'link'; | const MENUITEMKEY = 'link'; | ||||
const FIELD_URI = 'uri'; | |||||
const FIELD_NAME = 'name'; | |||||
public function getMenuItemTypeIcon() { | public function getMenuItemTypeIcon() { | ||||
return 'fa-link'; | return 'fa-link'; | ||||
} | } | ||||
public function getMenuItemTypeName() { | public function getMenuItemTypeName() { | ||||
return pht('Link'); | return pht('Link'); | ||||
} | } | ||||
public function canAddToObject($object) { | public function canAddToObject($object) { | ||||
return true; | return true; | ||||
} | } | ||||
public function getDisplayName( | public function getDisplayName( | ||||
PhabricatorProfileMenuItemConfiguration $config) { | PhabricatorProfileMenuItemConfiguration $config) { | ||||
return $this->getLinkName($config); | return $this->getLinkName($config); | ||||
} | } | ||||
public function buildEditEngineFields( | public function buildEditEngineFields( | ||||
PhabricatorProfileMenuItemConfiguration $config) { | PhabricatorProfileMenuItemConfiguration $config) { | ||||
return array( | return array( | ||||
id(new PhabricatorTextEditField()) | id(new PhabricatorTextEditField()) | ||||
->setKey('name') | ->setKey(self::FIELD_NAME) | ||||
->setLabel(pht('Name')) | ->setLabel(pht('Name')) | ||||
->setIsRequired(true) | ->setIsRequired(true) | ||||
->setValue($this->getLinkName($config)), | ->setValue($this->getLinkName($config)), | ||||
id(new PhabricatorTextEditField()) | id(new PhabricatorTextEditField()) | ||||
->setKey('uri') | ->setKey(self::FIELD_URI) | ||||
->setLabel(pht('URI')) | ->setLabel(pht('URI')) | ||||
->setIsRequired(true) | ->setIsRequired(true) | ||||
->setValue($this->getLinkURI($config)), | ->setValue($this->getLinkURI($config)), | ||||
id(new PhabricatorIconSetEditField()) | id(new PhabricatorIconSetEditField()) | ||||
->setKey('icon') | ->setKey('icon') | ||||
->setLabel(pht('Icon')) | ->setLabel(pht('Icon')) | ||||
->setIconSet(new PhabricatorProfileMenuItemIconSet()) | ->setIconSet(new PhabricatorProfileMenuItemIconSet()) | ||||
->setValue($this->getLinkIcon($config)), | ->setValue($this->getLinkIcon($config)), | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | $item = $this->newItem() | ||||
->setName($name) | ->setName($name) | ||||
->setIcon($icon_class); | ->setIcon($icon_class); | ||||
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_NAME) { | |||||
if ($this->isEmptyTransaction($value, $xactions)) { | |||||
$errors[] = $this->newRequiredError( | |||||
pht('You must choose a link name.'), | |||||
$field_key); | |||||
} | |||||
} | |||||
if ($field_key == self::FIELD_URI) { | |||||
if ($this->isEmptyTransaction($value, $xactions)) { | |||||
$errors[] = $this->newRequiredError( | |||||
pht('You must choose a URI to link to.'), | |||||
$field_key); | |||||
} | |||||
foreach ($xactions as $xaction) { | |||||
$new = $xaction['new']; | |||||
if (!$new) { | |||||
continue; | |||||
} | |||||
if ($new === $value) { | |||||
continue; | |||||
} | |||||
if (!$this->isValidLinkURI($new)) { | |||||
$errors[] = $this->newInvalidError( | |||||
pht( | |||||
'URI "%s" is not a valid link URI. It should be a full, valid '. | |||||
'URI beginning with a protocol like "%s".', | |||||
$new, | |||||
'https://'), | |||||
$xaction['xaction']); | |||||
} | |||||
} | |||||
} | |||||
return $errors; | |||||
} | |||||
} | } |