mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-08 18:34:47 +01:00
UI - add ability to customize header logo
Summary: Fixes T7165. Let users specify a file phid in config, and then use that file via an inline style tag. Also, cache the URI so that we don't have to query the file on every page load. Test Plan: {F319050} Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T7165 Differential Revision: https://secure.phabricator.com/D11886
This commit is contained in:
parent
33a06c97d3
commit
315aa4b000
4 changed files with 91 additions and 0 deletions
|
@ -1594,6 +1594,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCustomFieldNumericIndexStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldNumericIndexStorage.php',
|
||||
'PhabricatorCustomFieldStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStorage.php',
|
||||
'PhabricatorCustomFieldStringIndexStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStringIndexStorage.php',
|
||||
'PhabricatorCustomHeaderConfigType' => 'applications/config/custom/PhabricatorCustomHeaderConfigType.php',
|
||||
'PhabricatorDaemon' => 'infrastructure/daemon/PhabricatorDaemon.php',
|
||||
'PhabricatorDaemonConsoleController' => 'applications/daemon/controller/PhabricatorDaemonConsoleController.php',
|
||||
'PhabricatorDaemonController' => 'applications/daemon/controller/PhabricatorDaemonController.php',
|
||||
|
@ -4853,6 +4854,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCustomFieldNumericIndexStorage' => 'PhabricatorCustomFieldIndexStorage',
|
||||
'PhabricatorCustomFieldStorage' => 'PhabricatorLiskDAO',
|
||||
'PhabricatorCustomFieldStringIndexStorage' => 'PhabricatorCustomFieldIndexStorage',
|
||||
'PhabricatorCustomHeaderConfigType' => 'PhabricatorConfigOptionType',
|
||||
'PhabricatorDaemon' => 'PhutilDaemon',
|
||||
'PhabricatorDaemonConsoleController' => 'PhabricatorDaemonController',
|
||||
'PhabricatorDaemonController' => 'PhabricatorController',
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCustomHeaderConfigType
|
||||
extends PhabricatorConfigOptionType {
|
||||
|
||||
public function validateOption(PhabricatorConfigOption $option, $value) {
|
||||
if (phid_get_type($value) != PhabricatorFileFilePHIDType::TYPECONST) {
|
||||
throw new Exception(pht(
|
||||
'%s is not a valid file phid.', $value));
|
||||
}
|
||||
|
||||
$file = id(new PhabricatorFileQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withPHIDs(array($value))
|
||||
->executeOne();
|
||||
if (!$file) {
|
||||
throw new Exception(pht(
|
||||
'%s is not a valid file phid.', $value));
|
||||
}
|
||||
|
||||
$most_open_policy = PhabricatorPolicies::getMostOpenPolicy();
|
||||
if ($file->getViewPolicy() != $most_open_policy) {
|
||||
throw new Exception(pht(
|
||||
'Specified file %s has policy "%s" but should have policy "%s".',
|
||||
$value,
|
||||
$file->getViewPolicy(),
|
||||
$most_open_policy));
|
||||
}
|
||||
|
||||
if (!$file->isViewableImage()) {
|
||||
throw new Exception(pht(
|
||||
'Specified file %s is not a viewable image.',
|
||||
$value));
|
||||
}
|
||||
}
|
||||
|
||||
public static function getExampleConfig() {
|
||||
$config = 'PHID-FILE-abcd1234abcd1234abcd';
|
||||
return $config;
|
||||
}
|
||||
|
||||
}
|
|
@ -36,6 +36,8 @@ final class PhabricatorCoreConfigOptions
|
|||
'User Guide: Prototype Applications');
|
||||
$proto_doc_name = pht('User Guide: Prototype Applications');
|
||||
$applications_app_href = '/applications/';
|
||||
$custom_header_example =
|
||||
PhabricatorCustomHeaderConfigType::getExampleConfig();
|
||||
|
||||
return array(
|
||||
$this->newOption('phabricator.base-uri', 'string', null)
|
||||
|
@ -209,6 +211,27 @@ final class PhabricatorCoreConfigOptions
|
|||
->setLocked(true)
|
||||
->setDescription(
|
||||
pht('Custom HTML to show on the main Phabricator dashboard.')),
|
||||
$this->newOption(
|
||||
'ui.custom-header',
|
||||
'custom:PhabricatorCustomHeaderConfigType',
|
||||
null)
|
||||
->setSummary(
|
||||
pht('Customize the Phabricator logo.'))
|
||||
->setDescription(
|
||||
pht('You can customize the Phabricator logo by specifying the '.
|
||||
'phid for a viewable image you have uploaded to Phabricator '.
|
||||
'via the [[ /file/ | Files application]]. This image should '.
|
||||
'be:'."\n".
|
||||
' - 192px X 80px; while not enforced, images with these '.
|
||||
'dimensions will look best across devices.'."\n".
|
||||
' - have view policy public if [[ '.
|
||||
'/config/edit/policy.allow-public | `policy.allow-public`]] '.
|
||||
'is true and otherwise view policy user; mismatches in these '.
|
||||
'policy settings will result in a broken logo for some users.'.
|
||||
"\n\n".
|
||||
'You should restart your webserver after updating this value '.
|
||||
'to see this change take effect.'))
|
||||
->addExample($custom_header_example, pht('Valid Config')),
|
||||
$this->newOption('phabricator.cache-namespace', 'string', null)
|
||||
->setLocked(true)
|
||||
->setDescription(pht('Cache namespace.')),
|
||||
|
|
|
@ -236,6 +236,29 @@ final class PhabricatorMainMenuView extends AphrontView {
|
|||
}
|
||||
|
||||
private function renderPhabricatorLogo() {
|
||||
$style_logo = null;
|
||||
$custom_header = PhabricatorEnv::getEnvConfig('ui.custom-header');
|
||||
if ($custom_header) {
|
||||
$cache = PhabricatorCaches::getImmutableCache();
|
||||
$cache_key_logo = 'ui.custom-header.logo-phid.v1';
|
||||
$logo_uri = $cache->getKey($cache_key_logo);
|
||||
if (!$logo_uri) {
|
||||
$file = id(new PhabricatorFileQuery())
|
||||
->setViewer($this->getUser())
|
||||
->withPHIDs(array($custom_header))
|
||||
->executeOne();
|
||||
if ($file) {
|
||||
$logo_uri = $file->getViewURI();
|
||||
$cache->setKey($cache_key_logo, $logo_uri);
|
||||
}
|
||||
}
|
||||
if ($logo_uri) {
|
||||
$style_logo =
|
||||
'background-size: 96px 40px; '.
|
||||
'background-position: 0px 0px; '.
|
||||
'background-image: url('.$logo_uri.');';
|
||||
}
|
||||
}
|
||||
|
||||
return phutil_tag(
|
||||
'a',
|
||||
|
@ -260,6 +283,7 @@ final class PhabricatorMainMenuView extends AphrontView {
|
|||
'span',
|
||||
array(
|
||||
'class' => 'sprite-menu phabricator-main-menu-logo',
|
||||
'style' => $style_logo,
|
||||
),
|
||||
''),
|
||||
));
|
||||
|
|
Loading…
Add table
Reference in a new issue