Skip to content
Snippets Groups Projects
Unverified Commit 6f17db46 authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

Merge pull request #1552 from simplesamlphp/cleanup-hooks

Cleanup hooks
parents 322ceb4d 0fbe5533
No related branches found
No related tags found
No related merge requests found
coverage: coverage:
status: status:
project: yes project: yes
default:
target: 0%
threshold: 2%
patch: off patch: off
comment: comment:
layout: "diff" layout: "diff"
......
...@@ -205,12 +205,7 @@ function named `<module name>_hook_<hook name>`. ...@@ -205,12 +205,7 @@ function named `<module name>_hook_<hook name>`.
Each hook function accepts a single argument. This argument will be Each hook function accepts a single argument. This argument will be
passed by reference, which allows each hook to update that argument. passed by reference, which allows each hook to update that argument.
There is currently a single user of the hook interface - the front For an example of hook usage, see the cron module, which adds a link
page. The front page defines a hook named `frontpage`, which allows to its information page in the Configuration section of the admin
modules to add things to the different sections on the front page. For module, through the file `modules/cron/hooks/hook_configpage.php`.
an example of this, see the `modules/modinfo/hooks/hook_frontpage.php`
file in the
[modinfo module](https://github.com/simplesamlphp/simplesamlphp-module-modinfo).
...@@ -157,9 +157,6 @@ class Test ...@@ -157,9 +157,6 @@ class Test
]; ];
} }
Module::callHooks('configpage', $t);
Assert::isInstanceOf($t, Template::class);
$this->menu->addOption('logout', $this->authUtils->getAdminLogoutURL(), Translate::noop('Log out')); $this->menu->addOption('logout', $this->authUtils->getAdminLogoutURL(), Translate::noop('Log out'));
return $this->menu->insert($t); return $this->menu->insert($t);
} }
......
<?php
use SimpleSAML\Assert\Assert;
use SimpleSAML\Module;
/**
* Hook to add the modinfo module to the frontpage.
*
* @param array &$links The links on the frontpage, split into sections.
*/
function cron_hook_frontpage(array &$links): void
{
Assert::keyExists($links, 'links');
$links['config'][] = [
'href' => Module::getModuleURL('cron/info'),
'text' => '{cron:cron:link_cron}',
];
}
<?php
use SimpleSAML\Assert\Assert;
use SimpleSAML\Auth;
/**
* Hook to add the metadata for hosted entities to the frontpage.
*
* @param array &$metadataHosted The metadata links for hosted metadata on the frontpage.
*/
function saml_hook_metadata_hosted(array &$metadataHosted)
{
$sources = Auth\Source::getSourcesOfType('saml:SP');
foreach ($sources as $source) {
/** @var \SimpleSAML\Module\saml\Auth\Source\SP $source */
$metadata = $source->getMetadata();
$name = $metadata->getValue('name', null);
if ($name === null) {
$name = $metadata->getValue('OrganizationDisplayName', null);
}
if ($name === null) {
$name = $source->getAuthId();
}
$md = [
'entityid' => $source->getEntityId(),
'metadata-index' => $source->getEntityId(),
'metadata-set' => 'saml20-sp-hosted',
'metadata-url' => $source->getMetadataURL() . '?output=xhtml',
'name' => $name,
];
$metadataHosted[] = $md;
}
}
...@@ -118,11 +118,11 @@ class ModuleTest extends TestCase ...@@ -118,11 +118,11 @@ class ModuleTest extends TestCase
*/ */
public function testGetModuleHooks(): void public function testGetModuleHooks(): void
{ {
$hooks = Module::getModuleHooks('saml'); $hooks = Module::getModuleHooks('cron');
$this->assertArrayHasKey('metadata_hosted', $hooks); $this->assertArrayHasKey('configpage', $hooks);
$this->assertEquals('saml_hook_metadata_hosted', $hooks['metadata_hosted']['func']); $this->assertEquals('cron_hook_configpage', $hooks['configpage']['func']);
$expectedFile = dirname(__DIR__, 3) . '/modules/saml/hooks/hook_metadata_hosted.php'; $expectedFile = dirname(__DIR__, 3) . '/modules/cron/hooks/hook_configpage.php';
$this->assertEquals($expectedFile, $hooks['metadata_hosted']['file']); $this->assertEquals($expectedFile, $hooks['configpage']['file']);
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment