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:
status:
project: yes
default:
target: 0%
threshold: 2%
patch: off
comment:
layout: "diff"
......
......@@ -205,12 +205,7 @@ function named `<module name>_hook_<hook name>`.
Each hook function accepts a single argument. This argument will be
passed by reference, which allows each hook to update that argument.
There is currently a single user of the hook interface - the front
page. The front page defines a hook named `frontpage`, which allows
modules to add things to the different sections on the front page. For
an example of this, see the `modules/modinfo/hooks/hook_frontpage.php`
file in the
[modinfo module](https://github.com/simplesamlphp/simplesamlphp-module-modinfo).
For an example of hook usage, see the cron module, which adds a link
to its information page in the Configuration section of the admin
module, through the file `modules/cron/hooks/hook_configpage.php`.
......@@ -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'));
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
*/
public function testGetModuleHooks(): void
{
$hooks = Module::getModuleHooks('saml');
$this->assertArrayHasKey('metadata_hosted', $hooks);
$this->assertEquals('saml_hook_metadata_hosted', $hooks['metadata_hosted']['func']);
$expectedFile = dirname(__DIR__, 3) . '/modules/saml/hooks/hook_metadata_hosted.php';
$this->assertEquals($expectedFile, $hooks['metadata_hosted']['file']);
$hooks = Module::getModuleHooks('cron');
$this->assertArrayHasKey('configpage', $hooks);
$this->assertEquals('cron_hook_configpage', $hooks['configpage']['func']);
$expectedFile = dirname(__DIR__, 3) . '/modules/cron/hooks/hook_configpage.php';
$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