-
Open src/Plugin.php and confirm the file header:
<?php
namespace Detain\MyAdminSwift;
use Symfony\Component\EventDispatcher\GenericEvent;
Verify the use statement is present before proceeding.
-
Register the new hook in getHooks() by adding an entry to the returned array:
public static function getHooks()
{
return [
'system.settings' => [__CLASS__, 'getSettings'],
'function.requirements' => [__CLASS__, 'getRequirements'],
'your.event.name' => [__CLASS__, 'yourHandlerMethod'],
];
}
Verify the key follows the noun.verb dot-notation convention used by existing hooks.
-
Add the handler method immediately after the last handler in the file, before the closing }:
public static function yourHandlerMethod(GenericEvent $event)
{
$subject = $event->getSubject();
}
The parameter type hint must be GenericEvent (imported via use at the top).
-
For system.settings additions — call methods on $settings = $event->getSubject():
- Text field:
$settings->add_text_setting(_('Group'), _('Subgroup'), 'setting_key', _('Label'), _('Description'), CONSTANT_DEFAULT);
- Password field:
$settings->add_password_setting(_('Group'), _('Subgroup'), 'setting_key', _('Label'), _('Description'), CONSTANT_DEFAULT);
Full example matching the existing pattern:
public static function getSettings(GenericEvent $event)
{
$settings = $event->getSubject();
$settings->add_text_setting(_('Backups'), _('Swift'), 'swift_auth_url', _('Swift Auth URL'), _('Swift Auth URL'), SWIFT_AUTH_URL);
$settings->add_text_setting(_('Backups'), _('Swift'), 'swift_auth_v1_url', _('Swift Auth v1 URL'), _('Swift Auth v1 URL'), SWIFT_AUTH_V1_URL);
$settings->add_text_setting(_('Backups'), _('Swift'), 'swift_admin_user', _('Swift Admin User'), _('Swift Admin User'), SWIFT_ADMIN_USER);
$settings->add_password_setting(_('Backups'), _('Swift'), 'swift_admin_key', _('Swift Admin Key'), _('Swift Admin Key'), SWIFT_ADMIN_KEY);
}
Verify: 3 text settings + 1 password setting = testGetSettingsCallsSettingsMethods() asserts exactly these counts.
-
For function.requirements additions — call add_requirement on $loader = $event->getSubject():
public static function getRequirements(GenericEvent $event)
{
$loader = $event->getSubject();
$loader->add_requirement('class.Swift', '');
}
Path format: '/../vendor/detain/PACKAGE-NAME/src/ClassName.php'. Key format: 'class.ClassName'.
-
Update tests/PluginTest.php when the hook count or setting counts change:
- Hook count:
$this->assertCount(N, $hooks) in testGetHooksCount()
- Settings count:
$this->assertCount(N, $settings->textSettings) / $this->assertCount(N, $settings->passwordSettings) in testGetSettingsCallsSettingsMethods()
- Add a
testGetHooksContainsYourEvent() test asserting assertArrayHasKey('your.event.name', $hooks)
- Add a
testYourHandlerMethodIsStatic() test using ReflectionClass
-
Run tests to confirm nothing is broken:
vendor/bin/phpunit tests/PluginTest.php
All tests must pass before committing.