Skip to content

Commit

Permalink
pkp#10061 Updated highlights tab to respect the feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasraoni committed Jun 15, 2024
1 parent 067db41 commit 9714f07
Showing 1 changed file with 24 additions and 40 deletions.
64 changes: 24 additions & 40 deletions pages/admin/AdminHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,21 @@ public function contexts($args, $request)
* Display the administration settings page.
*
* @param array $args
* @param PKPRequest $request
* @param PKPRequest
*/
public function settings($args, $request)
public function settings($args, )
{
$this->setupTemplate($request);
$site = $request->getSite();
$dispatcher = $request->getDispatcher();
$this->setupTemplate();
$site = ->getSite();
$dispatcher = ->getDispatcher();

$apiUrl = $dispatcher->url($request, Application::ROUTE_API, Application::CONTEXT_ID_ALL, 'site');
$themeApiUrl = $dispatcher->url($request, Application::ROUTE_API, Application::CONTEXT_ID_ALL, 'site/theme');
$temporaryFileApiUrl = $dispatcher->url($request, Application::ROUTE_API, Application::CONTEXT_ID_ALL, 'temporaryFiles');
$announcementsApiUrl = $dispatcher->url($request, Application::ROUTE_API, Application::CONTEXT_ID_ALL, 'announcements');
$apiUrl = $dispatcher->url(, Application::ROUTE_API, Application::CONTEXT_ID_ALL, 'site');
$themeApiUrl = $dispatcher->url(, Application::ROUTE_API, Application::CONTEXT_ID_ALL, 'site/theme');
$temporaryFileApiUrl = $dispatcher->url(, Application::ROUTE_API, Application::CONTEXT_ID_ALL, 'temporaryFiles');
$announcementsApiUrl = $dispatcher->url(, Application::ROUTE_API, Application::CONTEXT_ID_ALL, 'announcements');

$publicFileManager = new PublicFileManager();
$baseUrl = $request->getBaseUrl() . '/' . $publicFileManager->getSiteFilesPath();
$baseUrl = ->getBaseUrl() . '/' . $publicFileManager->getSiteFilesPath();

$locales = $site->getSupportedLocaleNames();
$locales = array_map(fn (string $locale, string $name) => ['key' => $locale, 'label' => $name], array_keys($locales), $locales);
Expand All @@ -209,7 +209,7 @@ public function settings($args, $request)
$announcementsForm = new PKPAnnouncementForm($announcementsApiUrl, $locales, Repo::announcement()->getFileUploadBaseUrl(), $temporaryFileApiUrl);
$announcementsListPanel = $this->getAnnouncementsListPanel($announcementsApiUrl, $announcementsForm);

$templateMgr = TemplateManager::getManager($request);
$templateMgr = TemplateManager::getManager();

$templateMgr->setConstants([
'FORM_ANNOUNCEMENT_SETTINGS' => FORM_ANNOUNCEMENT_SETTINGS,
Expand Down Expand Up @@ -238,7 +238,7 @@ public function settings($args, $request)
$templateMgr->assign([
'breadcrumbs' => $breadcrumbs,
'pageTitle' => __('admin.siteSettings'),
'componentAvailability' => $this->siteSettingsAvailability($request),
'componentAvailability' => $this->siteSettingsAvailability(),
]);

$templateMgr->display('admin/settings.tpl');
Expand All @@ -247,20 +247,11 @@ public function settings($args, $request)
/**
* Business logic for site settings single/multiple contexts availability
*
* @param PKPRequest $request
*
* @return array [siteComponent, availability (bool)]
* @return array<string,bool> List of tabs, where the key is the tab name and the value its availability
*/
private function siteSettingsAvailability($request)
private function siteSettingsAvailability(): array
{
$tabsSingleContextAvailability = [
'siteSetup',
'languages',
'bulkEmails',
'statistics',
];

$tabs = [
$tabs = array_fill_keys([
'siteSetup',
'siteAppearance',
'sitePlugins',
Expand All @@ -274,27 +265,20 @@ private function siteSettingsAvailability($request)
'siteAppearanceSetup',
'statistics',
'announcements',
];

if (!Config::getVar('features', 'site_announcements')) {
$tabs = array_filter(
$tabs,
function($tab) { return $tab !== 'announcements'; }
);
}

$singleContextSite = (Services::get('context')->getCount() == 1);
], true);

$tabsAvailability = [];
$tabs['announcements'] = (bool) Config::getVar('features', 'site_announcements');
$tabs['highlights'] = (bool) Config::getVar('features', 'highlights');

foreach ($tabs as $tab) {
$tabsAvailability[$tab] = true;
if ($singleContextSite && !in_array($tab, $tabsSingleContextAvailability)) {
$tabsAvailability[$tab] = false;
$isSingleContextSite = Services::get('context')->getCount() < 2;
if ($isSingleContextSite) {
$multipleContextTabs = ['siteSetup', 'languages', 'bulkEmails', 'statistics'];
foreach ($multipleContextTabs as $tab) {
$tabs[$tab] = false;
}
}

return $tabsAvailability;
return $tabs;
}

/**
Expand Down

0 comments on commit 9714f07

Please sign in to comment.