Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/menuitem/PhabricatorLinkProfileMenuItem.php
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | private function getLinkURI( | ||||
return $config->getMenuItemProperty('uri'); | return $config->getMenuItemProperty('uri'); | ||||
} | } | ||||
private function getLinkTooltip( | private function getLinkTooltip( | ||||
PhabricatorProfileMenuItemConfiguration $config) { | PhabricatorProfileMenuItemConfiguration $config) { | ||||
return $config->getMenuItemProperty('tooltip'); | return $config->getMenuItemProperty('tooltip'); | ||||
} | } | ||||
private function isValidLinkURI($uri) { | protected function newMenuItemViewList( | ||||
return PhabricatorEnv::isValidURIForLink($uri); | |||||
} | |||||
protected function newNavigationMenuItems( | |||||
PhabricatorProfileMenuItemConfiguration $config) { | PhabricatorProfileMenuItemConfiguration $config) { | ||||
$icon = $this->getLinkIcon($config); | $icon = $this->getLinkIcon($config); | ||||
$name = $this->getLinkName($config); | $name = $this->getLinkName($config); | ||||
$href = $this->getLinkURI($config); | $uri = $this->getLinkURI($config); | ||||
$tooltip = $this->getLinkTooltip($config); | $tooltip = $this->getLinkTooltip($config); | ||||
if (!$this->isValidLinkURI($href)) { | |||||
$href = '#'; | |||||
} | |||||
$icon_object = id(new PhabricatorProfileMenuItemIconSet()) | $icon_object = id(new PhabricatorProfileMenuItemIconSet()) | ||||
->getIcon($icon); | ->getIcon($icon); | ||||
if ($icon_object) { | if ($icon_object) { | ||||
$icon_class = $icon_object->getIcon(); | $icon_class = $icon_object->getIcon(); | ||||
} else { | } else { | ||||
$icon_class = 'fa-link'; | $icon_class = 'fa-link'; | ||||
} | } | ||||
$item = $this->newItem() | $item = $this->newItemView() | ||||
->setHref($href) | ->setURI($uri) | ||||
->setName($name) | ->setName($name) | ||||
->setIcon($icon_class) | ->setIcon($icon_class) | ||||
->setTooltip($tooltip) | ->setTooltip($tooltip) | ||||
->setRel('noreferrer'); | ->setIsExternalLink(true); | ||||
return array( | return array( | ||||
$item, | $item, | ||||
); | ); | ||||
} | } | ||||
public function validateTransactions( | public function validateTransactions( | ||||
PhabricatorProfileMenuItemConfiguration $config, | PhabricatorProfileMenuItemConfiguration $config, | ||||
Show All 25 Lines | if ($field_key == self::FIELD_URI) { | ||||
if (!$new) { | if (!$new) { | ||||
continue; | continue; | ||||
} | } | ||||
if ($new === $value) { | if ($new === $value) { | ||||
continue; | continue; | ||||
} | } | ||||
if (!$this->isValidLinkURI($new)) { | if (!PhabricatorEnv::isValidURIForLink($new)) { | ||||
$errors[] = $this->newInvalidError( | $errors[] = $this->newInvalidError( | ||||
pht( | pht( | ||||
'URI "%s" is not a valid link URI. It should be a full, valid '. | 'URI "%s" is not a valid link URI. It should be a full, valid '. | ||||
'URI beginning with a protocol like "%s".', | 'URI beginning with a protocol like "%s".', | ||||
$new, | $new, | ||||
'https://'), | 'https://'), | ||||
$xaction['xaction']); | $xaction['xaction']); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return $errors; | return $errors; | ||||
} | } | ||||
} | } |