Differential D17235 Diff 41452 src/applications/search/menuitem/PhabricatorEditEngineProfileMenuItem.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/menuitem/PhabricatorEditEngineProfileMenuItem.php
<?php | <?php | ||||
final class PhabricatorEditEngineProfileMenuItem | final class PhabricatorEditEngineProfileMenuItem | ||||
extends PhabricatorProfileMenuItem { | extends PhabricatorProfileMenuItem { | ||||
const MENUITEMKEY = 'editengine'; | const MENUITEMKEY = 'editengine'; | ||||
const FIELD_FORM = 'formKey'; | |||||
private $form; | private $form; | ||||
public function getMenuItemTypeIcon() { | public function getMenuItemTypeIcon() { | ||||
return 'fa-plus'; | return 'fa-plus'; | ||||
} | } | ||||
public function getMenuItemTypeName() { | public function getMenuItemTypeName() { | ||||
return pht('Form'); | return pht('Form'); | ||||
Show All 30 Lines | public function willBuildNavigationItems(array $items) { | ||||
$builtin_map = array(); | $builtin_map = array(); | ||||
foreach ($form_engines as $engine_key => $form_engine) { | foreach ($form_engines as $engine_key => $form_engine) { | ||||
$builtin_map[$engine_key] = mpull($form_engine, null, 'getBuiltinKey'); | $builtin_map[$engine_key] = mpull($form_engine, null, 'getBuiltinKey'); | ||||
} | } | ||||
foreach ($items as $item) { | foreach ($items as $item) { | ||||
$key = $item->getMenuItemProperty('formKey'); | $key = $item->getMenuItemProperty('formKey'); | ||||
list($engine_key, $form_key) = explode('/', $key); | list($engine_key, $form_key) = PhabricatorEditEngine::splitFullKey($key); | ||||
if (is_numeric($form_key)) { | if (is_numeric($form_key)) { | ||||
$form = idx($form_ids, $form_key, null); | $form = idx($form_ids, $form_key, null); | ||||
$item->getMenuItem()->attachForm($form); | $item->getMenuItem()->attachForm($form); | ||||
} else if (isset($builtin_map[$engine_key][$form_key])) { | } else if (isset($builtin_map[$engine_key][$form_key])) { | ||||
$form = $builtin_map[$engine_key][$form_key]; | $form = $builtin_map[$engine_key][$form_key]; | ||||
$item->getMenuItem()->attachForm($form); | $item->getMenuItem()->attachForm($form); | ||||
} | } | ||||
} | } | ||||
Show All 15 Lines | final class PhabricatorEditEngineProfileMenuItem | ||||
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('formKey') | ->setKey(self::FIELD_FORM) | ||||
->setLabel(pht('Form')) | ->setLabel(pht('Form')) | ||||
->setIsRequired(true) | ->setIsRequired(true) | ||||
->setDatasource(new PhabricatorEditEngineDatasource()) | ->setDatasource(new PhabricatorEditEngineDatasource()) | ||||
->setSingleValue($config->getMenuItemProperty('formKey')), | ->setSingleValue($config->getMenuItemProperty('formKey')), | ||||
); | ); | ||||
} | } | ||||
private function getName( | private function getName( | ||||
Show All 20 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_FORM) { | |||||
if ($this->isEmptyTransaction($value, $xactions)) { | |||||
$errors[] = $this->newRequiredError( | |||||
pht('You must choose a form.'), | |||||
$field_key); | |||||
} | |||||
foreach ($xactions as $xaction) { | |||||
$new = $xaction['new']; | |||||
if (!$new) { | |||||
continue; | |||||
} | |||||
if ($new === $value) { | |||||
continue; | |||||
} | |||||
list($engine_key, $form_key) = PhabricatorEditEngine::splitFullKey( | |||||
$new); | |||||
$forms = id(new PhabricatorEditEngineConfigurationQuery()) | |||||
->setViewer($viewer) | |||||
->withEngineKeys(array($engine_key)) | |||||
->withIdentifiers(array($form_key)) | |||||
->execute(); | |||||
if (!$forms) { | |||||
$errors[] = $this->newInvalidError( | |||||
pht( | |||||
'Form "%s" is not a valid form which you have permission to '. | |||||
'see.', | |||||
$new), | |||||
$xaction['xaction']); | |||||
} | |||||
} | |||||
} | |||||
return $errors; | |||||
} | |||||
} | } |