diff --git a/php_profiler.module b/php_profiler.module
index 27ff2be..7b7fff8 100644
--- a/php_profiler.module
+++ b/php_profiler.module
@@ -8,46 +8,17 @@
  * This file is no longer required in Drupal 8.
  * @see https://www.drupal.org/node/2217931
  */
-
+use Drupal\Core\Hook\Attribute\LegacyHook;
+use Drupal\php_profiler\Hook\PhpProfilerHooks;
 use Drupal\Core\Form\FormStateInterface;
 
 /**
  * Implements hook_form_FORM_ID_alter().
  */
-function php_profiler_form_xhprof_config_alter(array &$form, FormStateInterface $form_state) {
-
-  // Load the existing config.
-  $config = \Drupal::config('xhprof.config');
-
-  // Add the config field for the XHGui URL.
-  $form['settings']['xhgui_url'] = [
-    '#type' => 'url',
-    '#title' => t('XHGui Storage URL'),
-    '#default_value' => $config->get('xhgui_url') ?: 'http://xhgui',
-    '#description' => t('Set the URL for the XHGui instance to log against.'),
-    '#states' => [
-      'visible' => [
-        ':input[name="storage"]' => ['value' => 'php_profiler.xhgui_upload'],
-      ],
-    ],
-  ];
-
-  // Add the token config.
-  $form['settings']['xhgui_token'] = [
-    '#type' => 'textfield',
-    '#title' => t('XHGui Token'),
-    '#default_value' => $config->get('xhgui_token'),
-    '#description' => t('XHGui token.'),
-    '#states' => [
-      'visible' => [
-        ':input[name="storage"]' => ['value' => 'php_profiler.xhgui_upload'],
-      ],
-    ],
-  ];
-
-  // Add submit handler to save additional config settings.
-  $form['#submit'][] = '_php_profiler_xhprof_config_submit';
-
+#[LegacyHook]
+function php_profiler_form_xhprof_config_alter(array &$form, FormStateInterface $form_state)
+{
+    \Drupal::service(PhpProfilerHooks::class)->formXhprofConfigAlter($form, $form_state);
 }
 
 /**
diff --git a/php_profiler.services.yml b/php_profiler.services.yml
index cc7394c..8583c60 100644
--- a/php_profiler.services.yml
+++ b/php_profiler.services.yml
@@ -4,3 +4,7 @@ services:
     class: Drupal\php_profiler\XHProfLib\Storage\XhGuiUploader
     tags:
       - { name: xhprof_storage }
+
+  Drupal\php_profiler\Hook\PhpProfilerHooks:
+    class: Drupal\php_profiler\Hook\PhpProfilerHooks
+    autowire: true
diff --git a/src/Hook/PhpProfilerHooks.php b/src/Hook/PhpProfilerHooks.php
new file mode 100644
index 0000000..1a3b26e
--- /dev/null
+++ b/src/Hook/PhpProfilerHooks.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Drupal\php_profiler\Hook;
+
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
+/**
+ * Hook implementations for php_profiler.
+ */
+class PhpProfilerHooks
+{
+    use StringTranslationTrait;
+    /**
+     * Implements hook_form_FORM_ID_alter().
+     */
+    #[Hook('form_xhprof_config_alter')]
+    public function formXhprofConfigAlter(array &$form, \Drupal\Core\Form\FormStateInterface $form_state)
+    {
+        // Load the existing config.
+        $config = \Drupal::config('xhprof.config');
+        // Add the config field for the XHGui URL.
+        $form['settings']['xhgui_url'] = [
+            '#type' => 'url',
+            '#title' => $this->t('XHGui Storage URL'),
+            '#default_value' => $config->get('xhgui_url') ?: 'http://xhgui',
+            '#description' => $this->t('Set the URL for the XHGui instance to log against.'),
+            '#states' => [
+                'visible' => [
+                    ':input[name="storage"]' => [
+                        'value' => 'php_profiler.xhgui_upload',
+                    ],
+                ],
+            ],
+        ];
+        // Add the token config.
+        $form['settings']['xhgui_token'] = [
+            '#type' => 'textfield',
+            '#title' => $this->t('XHGui Token'),
+            '#default_value' => $config->get('xhgui_token'),
+            '#description' => $this->t('XHGui token.'),
+            '#states' => [
+                'visible' => [
+                    ':input[name="storage"]' => [
+                        'value' => 'php_profiler.xhgui_upload',
+                    ],
+                ],
+            ],
+        ];
+        // Add submit handler to save additional config settings.
+        $form['#submit'][] = '_php_profiler_xhprof_config_submit';
+    }
+}
diff --git a/src/XHProfLib/Storage/XhGuiUploader.php b/src/XHProfLib/Storage/XhGuiUploader.php
index 89ef82d..004b20e 100644
--- a/src/XHProfLib/Storage/XhGuiUploader.php
+++ b/src/XHProfLib/Storage/XhGuiUploader.php
@@ -38,7 +38,7 @@ class XhGuiUploader implements StorageInterface {
    * @param string|null $token
    *   The token for the XHGui import.
    */
-  public function __construct(string $url = NULL, string $token = NULL) {
+  public function __construct(?string $url = NULL, ?string $token = NULL) {
     // phpcs:ignore
     $factory = \Drupal::configFactory();
     $configUrl = $factory->get('xhprof.config')->get('xhgui_url');
