diff --git a/src/applications/search/menuitem/PhabricatorApplicationProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorApplicationProfileMenuItem.php index 2cd6440cf5..1c4c8410f3 100644 --- a/src/applications/search/menuitem/PhabricatorApplicationProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorApplicationProfileMenuItem.php @@ -1,129 +1,142 @@ getApplication($config); - if ($app) { - return $app->getName(); - } else { - return pht('(Uninstalled Application)'); + $application = $this->getApplication($config); + if (!$application) { + return pht('(Restricted/Invalid Application)'); + } + + $name = $this->getName($config); + if (strlen($name)) { + return $name; } - return $app->getName(); + + return $application->getName(); } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorDatasourceEditField()) ->setKey(self::FIELD_APPLICATION) ->setLabel(pht('Application')) ->setIsRequired(true) ->setDatasource(new PhabricatorApplicationDatasource()) ->setIsRequired(true) ->setSingleValue($config->getMenuItemProperty('application')), + id(new PhabricatorTextEditField()) + ->setKey('name') + ->setLabel(pht('Name')) + ->setValue($this->getName($config)), ); } + private function getName( + PhabricatorProfileMenuItemConfiguration $config) { + return $config->getMenuItemProperty('name'); + } + private function getApplication( PhabricatorProfileMenuItemConfiguration $config) { $viewer = $this->getViewer(); $phid = $config->getMenuItemProperty('application'); $app = id(new PhabricatorApplicationQuery()) ->setViewer($viewer) ->withPHIDs(array($phid)) ->executeOne(); return $app; } protected function newNavigationMenuItems( PhabricatorProfileMenuItemConfiguration $config) { $viewer = $this->getViewer(); $app = $this->getApplication($config); if (!$app) { return array(); } $is_installed = PhabricatorApplication::isClassInstalledForViewer( get_class($app), $viewer); if (!$is_installed) { return array(); } $item = $this->newItem() ->setHref($app->getApplicationURI()) - ->setName($app->getName()) + ->setName($this->getDisplayName($config)) ->setIcon($app->getIcon()); return array( $item, ); } public function validateTransactions( PhabricatorProfileMenuItemConfiguration $config, $field_key, $value, array $xactions) { $viewer = $this->getViewer(); $errors = array(); if ($field_key == self::FIELD_APPLICATION) { if ($this->isEmptyTransaction($value, $xactions)) { $errors[] = $this->newRequiredError( pht('You must choose an application.'), $field_key); } foreach ($xactions as $xaction) { $new = $xaction['new']; if (!$new) { continue; } if ($new === $value) { continue; } $applications = id(new PhabricatorApplicationQuery()) ->setViewer($viewer) ->withPHIDs(array($new)) ->execute(); if (!$applications) { $errors[] = $this->newInvalidError( pht( 'Application "%s" is not a valid application which you have '. 'permission to see.', $new), $xaction['xaction']); } } } return $errors; } } diff --git a/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php index 2aab6eee34..c9a13bd4ab 100644 --- a/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php @@ -1,160 +1,160 @@ dashboard = $dashboard; return $this; } public function getDashboard() { $dashboard = $this->dashboard; if (!$dashboard) { return null; } else if ($dashboard->isArchived()) { return null; } return $dashboard; } public function willBuildNavigationItems(array $items) { $viewer = $this->getViewer(); $dashboard_phids = array(); foreach ($items as $item) { $dashboard_phids[] = $item->getMenuItemProperty('dashboardPHID'); } $dashboards = id(new PhabricatorDashboardQuery()) ->setViewer($viewer) ->withPHIDs($dashboard_phids) ->execute(); $dashboards = mpull($dashboards, null, 'getPHID'); foreach ($items as $item) { $dashboard_phid = $item->getMenuItemProperty('dashboardPHID'); $dashboard = idx($dashboards, $dashboard_phid, null); $item->getMenuItem()->attachDashboard($dashboard); } } public function getDisplayName( PhabricatorProfileMenuItemConfiguration $config) { $dashboard = $this->getDashboard(); if (!$dashboard) { return pht('(Restricted/Invalid Dashboard)'); } if (strlen($this->getName($config))) { return $this->getName($config); } else { return $dashboard->getName(); } } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( - id(new PhabricatorTextEditField()) - ->setKey('name') - ->setLabel(pht('Name')) - ->setValue($this->getName($config)), id(new PhabricatorDatasourceEditField()) ->setKey(self::FIELD_DASHBOARD) ->setLabel(pht('Dashboard')) ->setIsRequired(true) ->setDatasource(new PhabricatorDashboardDatasource()) ->setSingleValue($config->getMenuItemProperty('dashboardPHID')), + id(new PhabricatorTextEditField()) + ->setKey('name') + ->setLabel(pht('Name')) + ->setValue($this->getName($config)), ); } private function getName( PhabricatorProfileMenuItemConfiguration $config) { return $config->getMenuItemProperty('name'); } protected function newNavigationMenuItems( PhabricatorProfileMenuItemConfiguration $config) { $dashboard = $this->getDashboard(); if (!$dashboard) { return array(); } $icon = $dashboard->getIcon(); $name = $this->getDisplayName($config); $href = $dashboard->getViewURI(); $item = $this->newItem() ->setHref($href) ->setName($name) ->setIcon($icon); return array( $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; } } diff --git a/src/applications/search/menuitem/PhabricatorEditEngineProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorEditEngineProfileMenuItem.php index db4804996a..4b840d39e3 100644 --- a/src/applications/search/menuitem/PhabricatorEditEngineProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorEditEngineProfileMenuItem.php @@ -1,175 +1,175 @@ form = $form; return $this; } public function getForm() { $form = $this->form; if (!$form) { return null; } return $form; } public function willBuildNavigationItems(array $items) { $viewer = $this->getViewer(); $engines = PhabricatorEditEngine::getAllEditEngines(); $engine_keys = array_keys($engines); $forms = id(new PhabricatorEditEngineConfigurationQuery()) ->setViewer($viewer) ->withEngineKeys($engine_keys) ->withIsDisabled(false) ->execute(); $form_engines = mgroup($forms, 'getEngineKey'); $form_ids = $forms; $builtin_map = array(); foreach ($form_engines as $engine_key => $form_engine) { $builtin_map[$engine_key] = mpull($form_engine, null, 'getBuiltinKey'); } foreach ($items as $item) { $key = $item->getMenuItemProperty('formKey'); list($engine_key, $form_key) = PhabricatorEditEngine::splitFullKey($key); if (is_numeric($form_key)) { $form = idx($form_ids, $form_key, null); $item->getMenuItem()->attachForm($form); } else if (isset($builtin_map[$engine_key][$form_key])) { $form = $builtin_map[$engine_key][$form_key]; $item->getMenuItem()->attachForm($form); } } } public function getDisplayName( PhabricatorProfileMenuItemConfiguration $config) { $form = $this->getForm(); if (!$form) { return pht('(Restricted/Invalid Form)'); } if (strlen($this->getName($config))) { return $this->getName($config); } else { return $form->getName(); } } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( - id(new PhabricatorTextEditField()) - ->setKey('name') - ->setLabel(pht('Name')) - ->setValue($this->getName($config)), id(new PhabricatorDatasourceEditField()) ->setKey(self::FIELD_FORM) ->setLabel(pht('Form')) ->setIsRequired(true) ->setDatasource(new PhabricatorEditEngineDatasource()) ->setSingleValue($config->getMenuItemProperty('formKey')), + id(new PhabricatorTextEditField()) + ->setKey('name') + ->setLabel(pht('Name')) + ->setValue($this->getName($config)), ); } private function getName( PhabricatorProfileMenuItemConfiguration $config) { return $config->getMenuItemProperty('name'); } protected function newNavigationMenuItems( PhabricatorProfileMenuItemConfiguration $config) { $form = $this->getForm(); if (!$form) { return array(); } $engine = $form->getEngine(); $form_key = $form->getIdentifier(); $icon = $form->getIcon(); $name = $this->getDisplayName($config); $href = $engine->getEditURI(null, "form/{$form_key}/"); $item = $this->newItem() ->setHref($href) ->setName($name) ->setIcon($icon); return array( $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; } } diff --git a/src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php index 364a68e4b8..aadabd179a 100644 --- a/src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php @@ -1,160 +1,160 @@ project = $project; return $this; } public function getProject() { $project = $this->project; if (!$project) { return null; } else if ($project->isArchived()) { return null; } return $project; } public function willBuildNavigationItems(array $items) { $viewer = $this->getViewer(); $project_phids = array(); foreach ($items as $item) { $project_phids[] = $item->getMenuItemProperty('project'); } $projects = id(new PhabricatorProjectQuery()) ->setViewer($viewer) ->withPHIDs($project_phids) ->needImages(true) ->execute(); $projects = mpull($projects, null, 'getPHID'); foreach ($items as $item) { $project_phid = $item->getMenuItemProperty('project'); $project = idx($projects, $project_phid, null); $item->getMenuItem()->attachProject($project); } } public function getDisplayName( PhabricatorProfileMenuItemConfiguration $config) { $project = $this->getProject(); if (!$project) { return pht('(Restricted/Invalid Project)'); } if (strlen($this->getName($config))) { return $this->getName($config); } else { return $project->getName(); } } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( - id(new PhabricatorTextEditField()) - ->setKey('name') - ->setLabel(pht('Name')) - ->setValue($this->getName($config)), id(new PhabricatorDatasourceEditField()) ->setKey(self::FIELD_PROJECT) ->setLabel(pht('Project')) ->setIsRequired(true) ->setDatasource(new PhabricatorProjectDatasource()) ->setSingleValue($config->getMenuItemProperty('project')), + id(new PhabricatorTextEditField()) + ->setKey('name') + ->setLabel(pht('Name')) + ->setValue($this->getName($config)), ); } private function getName( PhabricatorProfileMenuItemConfiguration $config) { return $config->getMenuItemProperty('name'); } protected function newNavigationMenuItems( PhabricatorProfileMenuItemConfiguration $config) { $project = $this->getProject(); if (!$project) { return array(); } $picture = $project->getProfileImageURI(); $name = $this->getDisplayName($config); $href = $project->getURI(); $item = $this->newItem() ->setHref($href) ->setName($name) ->setProfileImage($picture); return array( $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; } }