diff --git a/cookie_script.module b/cookie_script.module
index 054f5e9..fa8e544 100644
--- a/cookie_script.module
+++ b/cookie_script.module
@@ -5,51 +5,30 @@
  * Module file for cookie_script.
  */
 
+use Drupal\Core\Hook\Attribute\LegacyHook;
+use Drupal\cookie_script\Hook\CookieScriptHooks;
 use Drupal\Core\Routing\RouteMatchInterface;
 
 /**
  * Implements hook_help().
  */
+#[LegacyHook]
 function cookie_script_help($route_name, RouteMatchInterface $route_match) {
-  switch ($route_name) {
-    // Main module help for the cookie_script module.
-    case 'help.page.cookie_script':
-      $output = '';
-      $output .= '<h3>' . t('About') . '</h3>';
-      $output .= '<p>' . t('Cookie Script Integration module.
-
-      https://cookie-script.com/') . '</p>';
-      return $output;
-
-    default:
-  }
+  return \Drupal::service(CookieScriptHooks::class)->help($route_name, $route_match);
 }
 
 /**
  * Implements hook_library_info_build().
  */
+#[LegacyHook]
 function cookie_script_library_info_build() {
-  $libraries = [];
-
-  $id = \Drupal::config('cookie_script.settings')->get('id');
-  if (!empty($id)) {
-    $libraries['base'] = [
-      'version' => '1.x',
-      'js' => [
-        '//cdn.cookie-script.com/s/' . $id . '.js' => [
-          'type' => 'external',
-          'minified' => TRUE,
-        ],
-      ],
-    ];
-  }
-
-  return $libraries;
+  return \Drupal::service(CookieScriptHooks::class)->libraryInfoBuild();
 }
 
 /**
  * Implements hook_preprocess_page().
  */
+#[LegacyHook]
 function cookie_script_preprocess_page(&$variables) {
-  $variables['#attached']['library'][] = 'cookie_script/base';
+  \Drupal::service(CookieScriptHooks::class)->preprocessPage($variables);
 }
diff --git a/cookie_script.services.yml b/cookie_script.services.yml
new file mode 100644
index 0000000..60c95f9
--- /dev/null
+++ b/cookie_script.services.yml
@@ -0,0 +1,5 @@
+
+services:
+  Drupal\cookie_script\Hook\CookieScriptHooks:
+    class: Drupal\cookie_script\Hook\CookieScriptHooks
+    autowire: true
diff --git a/src/Hook/CookieScriptHooks.php b/src/Hook/CookieScriptHooks.php
new file mode 100644
index 0000000..681bded
--- /dev/null
+++ b/src/Hook/CookieScriptHooks.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace Drupal\cookie_script\Hook;
+
+use Drupal\Core\Routing\RouteMatchInterface;
+use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
+
+/**
+ * Hook implementations for cookie_script.
+ */
+class CookieScriptHooks {
+  use StringTranslationTrait;
+
+  /**
+   * Implements hook_help().
+   */
+  #[Hook('help')]
+  public function help($route_name, RouteMatchInterface $route_match) {
+    switch ($route_name) {
+      // Main module help for the cookie_script module.
+      case 'help.page.cookie_script':
+        $output = '';
+        $output .= '<h3>' . $this->t('About') . '</h3>';
+        $output .= '<p>' . $this->t('Cookie Script Integration module.
+
+      https://cookie-script.com/') . '</p>';
+        return $output;
+
+      default:
+    }
+  }
+
+  /**
+   * Implements hook_library_info_build().
+   */
+  #[Hook('library_info_build')]
+  public static function libraryInfoBuild() {
+    $libraries = [];
+    $id = \Drupal::config('cookie_script.settings')->get('id');
+    if (!empty($id)) {
+      $libraries['base'] = [
+        'version' => '1.x',
+        'js' => [
+          '//cdn.cookie-script.com/s/' . $id . '.js' => [
+            'type' => 'external',
+            'minified' => TRUE,
+          ],
+        ],
+      ];
+    }
+    return $libraries;
+  }
+
+  /**
+   * Implements hook_preprocess_page().
+   */
+  #[Hook('preprocess_page')]
+  public static function preprocessPage(&$variables) {
+    $variables['#attached']['library'][] = 'cookie_script/base';
+  }
+
+}
