-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLanguageToggleByFlagPlugin.php
More file actions
82 lines (70 loc) · 2.39 KB
/
Copy pathLanguageToggleByFlagPlugin.php
File metadata and controls
82 lines (70 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* @file plugins/blocks/languageToggleByFlagBlock/LanguageToggleByFlagPlugin.inc.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Copyright (c) 2019-2024 Lepidus Tecnologia
*
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class LanguageToggleByFlagPlugin
*
* @ingroup plugins_blocks_languageToggleByFlag
*
* @brief Class for language selector by flag block plugin
*/
namespace APP\plugins\blocks\languageToggleByFlag;
use APP\core\Application;
use PKP\config\Config;
use PKP\core\PKPSessionGuard;
use PKP\facades\Locale;
use PKP\i18n\LocaleMetadata;
use PKP\plugins\BlockPlugin;
class LanguageToggleByFlagPlugin extends BlockPlugin
{
public function getInstallSitePluginSettingsFile()
{
return $this->getPluginPath() . '/settings.xml';
}
public function getContextSpecificPluginSettingsFile()
{
return $this->getPluginPath() . '/settings.xml';
}
public function getSeq($contextId = null)
{
if (!Config::getVar('general', 'installed')) {
return 3;
}
return parent::getSeq($contextId);
}
public function getDisplayName()
{
return __('plugins.block.languageToggleByFlag.displayName');
}
public function getDescription()
{
return __('plugins.block.languageToggleByFlag.description');
}
public function getContents($templateMgr, $request = null)
{
$templateMgr->assign('isPostRequest', $request->isPost());
if (!PKPSessionGuard::isSessionDisable()) {
$request ??= Application::get()->getRequest();
$context = $request->getContext();
$locales = Locale::getFormattedDisplayNames(
isset($context)
? $context->getSupportedLocales()
: $request->getSite()->getSupportedLocales(),
Locale::getLocales(),
LocaleMetadata::LANGUAGE_LOCALE_ONLY
);
} else {
$locales = Locale::getFormattedDisplayNames(null, null, LocaleMetadata::LANGUAGE_LOCALE_ONLY);
$templateMgr->assign('languageToggleNoUser', true);
}
$templateMgr->assign('enableLanguageToggle', count($locales) > 1);
$templateMgr->assign('languageToggleLocales', $locales);
return parent::getContents($templateMgr, $request);
}
}