Skip to content
Snippets Groups Projects
Unverified Commit d42f26f3 authored by Jaime Pérez Crespo's avatar Jaime Pérez Crespo
Browse files

Create a new "configpage" hook for those modules that need to inject anything...

Create a new "configpage" hook for those modules that need to inject anything in the configuration page.

This allows us to change the signature of the hook, so that we pass it the \SimpleSAML\XHTML\Template object and then the hook can not only add data to be passed to the twig template, but also add its own translation domain. This was needed because many modules were putting their translations inside "core", and when moving those to the modules themselves, the new translation system cannot perform the translation because only the translations for the current module in use are loaded (in the config page, that's the core module). Therefore, we needed a way to get the Localization instance from the template, and a way to pass that to the hook so that the hook can register the translations for its own module.
parent 409862ba
Branches
Tags
No related merge requests found
Showing
with 106 additions and 71 deletions
...@@ -126,7 +126,7 @@ class Localization ...@@ -126,7 +126,7 @@ class Localization
} }
/* /**
* Add a new translation domain from a module * Add a new translation domain from a module
* (We're assuming that each domain only exists in one place) * (We're assuming that each domain only exists in one place)
* *
...@@ -142,7 +142,7 @@ class Localization ...@@ -142,7 +142,7 @@ class Localization
} }
/* /**
* Add a new translation domain * Add a new translation domain
* (We're assuming that each domain only exists in one place) * (We're assuming that each domain only exists in one place)
* *
......
...@@ -583,6 +583,17 @@ class Template extends Response ...@@ -583,6 +583,17 @@ class Template extends Response
} }
/**
* Return the internal localization object used by this template.
*
* @return \SimpleSAML\Locale\Localization The localization object that will be used with this template.
*/
public function getLocalization()
{
return $this->localization;
}
/** /**
* Get the current instance of Twig in use. * Get the current instance of Twig in use.
* *
......
...@@ -58,5 +58,8 @@ ...@@ -58,5 +58,8 @@
}, },
"consentadmin_purpose": { "consentadmin_purpose": {
"en": "The purpose of the service is" "en": "The purpose of the service is"
},
"link_consentAdmin": {
"en": "Consent administration"
} }
} }
...@@ -598,5 +598,10 @@ ...@@ -598,5 +598,10 @@
"cs": "\u00da\u010del slu\u017eby je", "cs": "\u00da\u010del slu\u017eby je",
"eu": "Zerbitzuaren xedea hau da", "eu": "Zerbitzuaren xedea hau da",
"el": "\u039f \u03c3\u03ba\u03bf\u03c0\u03cc\u03c2 \u03c4\u03b7\u03c2 \u03c5\u03c0\u03b7\u03c1\u03b5\u03c3\u03af\u03b1\u03c2 \u03b5\u03af\u03bd\u03b1\u03b9" "el": "\u039f \u03c3\u03ba\u03bf\u03c0\u03cc\u03c2 \u03c4\u03b7\u03c2 \u03c5\u03c0\u03b7\u03c1\u03b5\u03c3\u03af\u03b1\u03c2 \u03b5\u03af\u03bd\u03b1\u03b9"
},
"link_consentAdmin": {
"es": "Administración del consentimiento",
"no": "Samtykke administrasjon",
"nn": "Samtykke administrasjon"
} }
} }
<?php
/**
* Hook to add the consentAdmin module to the config page.
*
* @param \SimpleSAML\XHTML\Template The template that we should alter in this hook.
*/
function consentAdmin_hook_configpage(\SimpleSAML\XHTML\Template &$template)
{
$template->data['links_config']['consentAdmin'] = [
'href' => SimpleSAML\Module::getModuleURL('consentAdmin/consentAdmin.php'),
'text' => '{consentAdmin:consentadmin:link_consentAdmin}',
];
$config = \SimpleSAML\Configuration::getInstance();
if ($config->getBoolean('usenewui', false)) {
$template->getLocalization()->addModuleDomain('consentAdmin');
}
}
<?php
/**
* Hook to add the consentAdmin module to the frontpage.
*
* @param array &$links The links on the frontpage, split into sections.
*/
function consentAdmin_hook_frontpage(&$links)
{
assert(is_array($links));
assert(array_key_exists('links', $links));
$links['config'][] = [
'href' => SimpleSAML\Module::getModuleURL('consentAdmin/consentAdmin.php'),
'text' => '{core:frontpage:link_consentAdmin}',
];
}
...@@ -110,27 +110,9 @@ ...@@ -110,27 +110,9 @@
"link_cleardiscochoices": { "link_cleardiscochoices": {
"en": "Delete my choices of IdP in the IdP discovery services" "en": "Delete my choices of IdP in the IdP discovery services"
}, },
"link_sanitycheck": {
"en": "Sanity check of your SimpleSAMLphp setup"
},
"link_consentAdmin": {
"en": "Consent Administration"
},
"link_memcacheMonitor": {
"en": "MemCache Statistics"
},
"link_oauth": { "link_oauth": {
"en": "OAuth Consumer Registry" "en": "OAuth Consumer Registry"
}, },
"link_cron": {
"en": "Cron module information page"
},
"link_statistics": {
"en": "Show statistics"
},
"link_statistics_metadata": {
"en": "Show statistics metadata"
},
"link_metarefresh": { "link_metarefresh": {
"en": "Metarefresh: fetch metadata" "en": "Metarefresh: fetch metadata"
}, },
......
...@@ -53,6 +53,8 @@ $allLinks = [ ...@@ -53,6 +53,8 @@ $allLinks = [
'federation' => &$links_federation, 'federation' => &$links_federation,
]; ];
\SimpleSAML\Module::callHooks('frontpage', $allLinks); \SimpleSAML\Module::callHooks('frontpage', $allLinks);
\SimpleSAML\Logger::debug('The "frontpage" hook has been deprecated for the configuration page. Implement the '.'
"configpage" hook instead.');
// Check for updates. Store the remote result in the session so we // Check for updates. Store the remote result in the session so we
// don't need to fetch it on every access to this page. // don't need to fetch it on every access to this page.
...@@ -197,4 +199,6 @@ $t->data['requiredmap'] = [ ...@@ -197,4 +199,6 @@ $t->data['requiredmap'] = [
$t->data['version'] = $config->getVersion(); $t->data['version'] = $config->getVersion();
$t->data['directory'] = dirname(dirname(dirname(dirname(__FILE__)))); $t->data['directory'] = dirname(dirname(dirname(dirname(__FILE__))));
\SimpleSAML\Module::callHooks('configpage', $t);
$t->show(); $t->show();
...@@ -22,5 +22,8 @@ ...@@ -22,5 +22,8 @@
}, },
"cron_report_title": { "cron_report_title": {
"en": "Cron report" "en": "Cron report"
},
"link_cron": {
"en": "Cron module information page"
} }
} }
\ No newline at end of file
...@@ -254,5 +254,10 @@ ...@@ -254,5 +254,10 @@
"af": "Cron verslag", "af": "Cron verslag",
"pt-br": "Relat\u00f3rio do cron", "pt-br": "Relat\u00f3rio do cron",
"el": "\u0391\u03bd\u03b1\u03c6\u03bf\u03c1\u03ac cron" "el": "\u0391\u03bd\u03b1\u03c6\u03bf\u03c1\u03ac cron"
},
"link_cron": {
"es": "Informe de cron",
"no": "Informasjon om cron",
"nn": "Informasjon om cron"
} }
} }
<?php
/**
* Hook to add the cron module to the config page.
*
* @param \SimpleSAML\XHTML\Template &$template The template that we should alter in this hook.
*/
function cron_hook_configpage(\SimpleSAML\XHTML\Template &$template)
{
$template->data['links_config']['cron'] = [
'href' => SimpleSAML\Module::getModuleURL('cron/croninfo.php'),
'text' => '{cron:cron:link_cron}',
];
$config = \SimpleSAML\Configuration::getInstance();
if ($config->getBoolean('usenewui', false)) {
$template->getLocalization()->addModuleDomain('cron');
}
}
<?php
/**
* Hook to add the modinfo module to the frontpage.
*
* @param array &$links The links on the frontpage, split into sections.
*/
function cron_hook_frontpage(&$links)
{
assert(is_array($links));
assert(array_key_exists('links', $links));
$links['config'][] = [
'href' => SimpleSAML\Module::getModuleURL('cron/croninfo.php'),
'text' => '{core:frontpage:link_cron}',
];
}
...@@ -63,3 +63,5 @@ msgstr "Here are the result for the cron job execution:" ...@@ -63,3 +63,5 @@ msgstr "Here are the result for the cron job execution:"
msgid "Cron result page" msgid "Cron result page"
msgstr "Cron result page" msgstr "Cron result page"
msgid "{cron:cron:link_cron}"
msgstr "Cron module information page"
...@@ -63,3 +63,5 @@ msgstr "Aqui están los resultados de las tareas en la ejecución del cron:" ...@@ -63,3 +63,5 @@ msgstr "Aqui están los resultados de las tareas en la ejecución del cron:"
msgid "Cron result page" msgid "Cron result page"
msgstr "Página de resultado del cron" msgstr "Página de resultado del cron"
msgid "{cron:cron:link_cron}"
msgstr "Informe de cron"
...@@ -63,3 +63,5 @@ msgstr "Her er resultatene fra kjøring av cron-jobben:" ...@@ -63,3 +63,5 @@ msgstr "Her er resultatene fra kjøring av cron-jobben:"
msgid "Cron result page" msgid "Cron result page"
msgstr "Cron resultatside" msgstr "Cron resultatside"
msgid "{cron:cron:link_cron}"
msgstr "Informasjon om cron"
...@@ -63,3 +63,5 @@ msgstr "Her er resultata frå køyring av cron-jobben:" ...@@ -63,3 +63,5 @@ msgstr "Her er resultata frå køyring av cron-jobben:"
msgid "Cron result page" msgid "Cron result page"
msgstr "Cron resultatside" msgstr "Cron resultatside"
msgid "{cron:cron:link_cron}"
msgstr "Informasjon om cron"
...@@ -142,5 +142,8 @@ ...@@ -142,5 +142,8 @@
}, },
"reclaimed": { "reclaimed": {
"en": "Number of times an entry was stored using memory from an expired entry" "en": "Number of times an entry was stored using memory from an expired entry"
},
"link_memcacheMonitor": {
"en": "Memcache statistics"
} }
} }
...@@ -549,5 +549,10 @@ ...@@ -549,5 +549,10 @@
"cs": "Celkov\u00e9 dostupn\u00e9 \u00falo\u017ei\u0161t\u011b", "cs": "Celkov\u00e9 dostupn\u00e9 \u00falo\u017ei\u0161t\u011b",
"eu": "Ustiatutako biltegiraketa guztira", "eu": "Ustiatutako biltegiraketa guztira",
"el": "\u0394\u03b9\u03b1\u03b8\u03ad\u03c3\u03b9\u03bc\u03bf\u03c2 \u03c7\u03ce\u03c1\u03bf\u03c2 \u03b1\u03c0\u03bf\u03b8\u03ae\u03ba\u03b5\u03c5\u03c3\u03b7\u03c2" "el": "\u0394\u03b9\u03b1\u03b8\u03ad\u03c3\u03b9\u03bc\u03bf\u03c2 \u03c7\u03ce\u03c1\u03bf\u03c2 \u03b1\u03c0\u03bf\u03b8\u03ae\u03ba\u03b5\u03c5\u03c3\u03b7\u03c2"
},
"link_memcacheMonitor": {
"es": "Estadísticas de memcache",
"no": "Memcache statistikker",
"nn": "Memcache statistikkar"
} }
} }
<?php
/**
* Hook to add the memcacheMonitor module to the config page.
*
* @param \SimpleSAML\XHTML\Template &$template The template that we should alter in this hook.
*/
function memcacheMonitor_hook_configpage(\SimpleSAML\XHTML\Template &$template)
{
$template->data['links_config']['memcacheMonitor'] = [
'href' => SimpleSAML\Module::getModuleURL('memcacheMonitor/memcachestat.php'),
'text' => '{memcacheMonitor:memcachestat:link_memcacheMonitor}',
];
$config = \SimpleSAML\Configuration::getInstance();
if ($config->getBoolean('usenewui', false)) {
$template->getLocalization()->addModuleDomain('memcacheMonitor');
}
}
<?php
/**
* Hook to add the simple consenet admin module to the frontpage.
*
* @param array &$links The links on the frontpage, split into sections.
*/
function memcacheMonitor_hook_frontpage(&$links)
{
assert(is_array($links));
assert(array_key_exists('links', $links));
$links['config'][] = [
'href' => SimpleSAML\Module::getModuleURL('memcacheMonitor/memcachestat.php'),
'text' => '{core:frontpage:link_memcacheMonitor}',
];
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment