diff --git a/field_longtext_pager.module b/field_longtext_pager.module
index 449c74a..a168652 100644
--- a/field_longtext_pager.module
+++ b/field_longtext_pager.module
@@ -7,7 +7,8 @@
  * Inspiration and algorithms adapted from the Drupal 7 smart_paging module.
  * Credit and gratitude to Roland Michael dela Peña.
  */
-
+use Drupal\Core\Hook\Attribute\LegacyHook;
+use Drupal\field_longtext_pager\Hook\FieldLongtextPagerHooks;
 use Drupal\Component\Utility\Html;
 use Drupal\Core\Routing\RouteMatchInterface;
 use Drupal\Core\Url;
@@ -15,33 +16,10 @@ use Drupal\Core\Url;
 /**
  * Implements hook_help().
  */
-function field_longtext_pager_help(
-  $route_name,
-  RouteMatchInterface $route_match,
-) {
-  switch ($route_name) {
-    case 'help.page.field_longtext_pager':
-      $text = file_get_contents(__DIR__ . '/README.md');
-
-      if (!\Drupal::moduleHandler()->moduleExists('markdown')) {
-        return '<pre>' . $text . '</pre>';
-      }
-
-      try {
-        $filter_manager = \Drupal::service('plugin.manager.filter');
-        $settings = \Drupal::configFactory()
-          ->get('markdown.settings')
-          ->getRawData();
-        $config = ['settings' => $settings];
-        $filter = $filter_manager->createInstance('markdown', $config);
-        return $filter->process($text, 'en');
-      }
-      catch (\Exception $e) {
-        // Fallback to plain text if the Markdown filter is misconfigured.
-        return '<pre>' . $text . '</pre>';
-      }
-  }
-  return NULL;
+#[LegacyHook]
+function field_longtext_pager_help($route_name, RouteMatchInterface $route_match)
+{
+    return \Drupal::service(FieldLongtextPagerHooks::class)->help($route_name, $route_match);
 }
 
 /**
@@ -71,61 +49,10 @@ function field_longtext_pager_get_pager_id(
  *
  * Detects pager fields and adds attributes to markup to enable Ajax paging.
  */
-function field_longtext_pager_entity_display_build_alter(&$build, $context) {
-  $view_mode = $context['view_mode'];
-
-  foreach ($build as $field_name => $field) {
-
-    if (!empty($field['#field_type'])
-      && isset($field['#formatter'])
-      && $field['#formatter'] === 'longtext_pager'
-    ) {
-      $entity_type = $context['entity']->getEntityTypeId();
-      $entity_id = $context['entity']->id();
-      $bundle = $context['entity']->bundle();
-
-      $field_settings_helper = \Drupal::service(
-        'field_longtext_pager.field_settings_helper'
-      );
-
-      $pager_id = field_longtext_pager_get_pager_id(
-        $entity_type,
-        $bundle,
-        $field_name
-      );
-
-      $ajax_enabled = $field_settings_helper->ajaxEnabled(
-        $entity_type,
-        $bundle,
-        $field_name,
-        $view_mode
-      );
-
-      if ($ajax_enabled) {
-        $build[$field_name]['#attributes']['data-ajax_pager'] = $pager_id;
-
-        $actual_field_name = $field['#field_name'];
-        $build[$actual_field_name]['#attached']['library'][] =
-          'field_longtext_pager/ajax_pager.js';
-
-        $ajax_url = Url::fromRoute('field_longtext_pager.ajax_pager.api')
-          ->toString();
-
-        $build[$actual_field_name]['#attached']['drupalSettings']['ajax_pager'][$pager_id]
-          = [
-            'ajax_url' => $ajax_url,
-            'ajax_pager' => [
-              'pager_id' => $pager_id,
-              'entity_id' => $entity_id,
-              'field_name' => $field['#field_name'],
-              'entity_type' => $field['#entity_type'],
-              'bundle' => $field['#bundle'],
-              'view_mode' => $view_mode,
-            ],
-          ];
-      }
-    }
-  }
+#[LegacyHook]
+function field_longtext_pager_entity_display_build_alter(&$build, $context)
+{
+    \Drupal::service(FieldLongtextPagerHooks::class)->entityDisplayBuildAlter($build, $context);
 }
 
 /**
diff --git a/field_longtext_pager.services.yml b/field_longtext_pager.services.yml
index 9d3c17c..cf516b9 100644
--- a/field_longtext_pager.services.yml
+++ b/field_longtext_pager.services.yml
@@ -10,3 +10,7 @@ services:
   field_longtext_pager.field_settings_helper:
     class: Drupal\field_longtext_pager\FieldSettingsHelper
     arguments: ['@entity_type.manager']
+
+  Drupal\field_longtext_pager\Hook\FieldLongtextPagerHooks:
+    class: Drupal\field_longtext_pager\Hook\FieldLongtextPagerHooks
+    autowire: true
diff --git a/src/Hook/FieldLongtextPagerHooks.php b/src/Hook/FieldLongtextPagerHooks.php
new file mode 100644
index 0000000..2ab955b
--- /dev/null
+++ b/src/Hook/FieldLongtextPagerHooks.php
@@ -0,0 +1,78 @@
+<?php
+
+namespace Drupal\field_longtext_pager\Hook;
+
+use Drupal\Component\Utility\Html;
+use Drupal\Core\Routing\RouteMatchInterface;
+use Drupal\Core\Url;
+use Drupal\Core\Hook\Attribute\Hook;
+/**
+ * Hook implementations for field_longtext_pager.
+ */
+class FieldLongtextPagerHooks
+{
+    /**
+     * Implements hook_help().
+     */
+    #[Hook('help')]
+    public function help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match)
+    {
+        switch ($route_name) {
+            case 'help.page.field_longtext_pager':
+                $text = file_get_contents(__DIR__ . '/README.md');
+                if (!\Drupal::moduleHandler()->moduleExists('markdown')) {
+                    return '<pre>' . $text . '</pre>';
+                }
+                try {
+                    $filter_manager = \Drupal::service('plugin.manager.filter');
+                    $settings = \Drupal::configFactory()->get('markdown.settings')->getRawData();
+                    $config = [
+                        'settings' => $settings,
+                    ];
+                    $filter = $filter_manager->createInstance('markdown', $config);
+                    return $filter->process($text, 'en');
+                } catch (\Exception $e) {
+                    // Fallback to plain text if the Markdown filter is misconfigured.
+                    return '<pre>' . $text . '</pre>';
+                }
+        }
+        return NULL;
+    }
+    /**
+     * Implements hook_entity_display_build_alter().
+     *
+     * Detects pager fields and adds attributes to markup to enable Ajax paging.
+     */
+    #[Hook('entity_display_build_alter')]
+    public function entityDisplayBuildAlter(&$build, $context)
+    {
+        $view_mode = $context['view_mode'];
+        foreach ($build as $field_name => $field) {
+            if (!empty($field['#field_type']) && isset($field['#formatter']) && $field['#formatter'] === 'longtext_pager') {
+                $entity_type = $context['entity']->getEntityTypeId();
+                $entity_id = $context['entity']->id();
+                $bundle = $context['entity']->bundle();
+                $field_settings_helper = \Drupal::service('field_longtext_pager.field_settings_helper');
+                $pager_id = field_longtext_pager_get_pager_id($entity_type, $bundle, $field_name);
+                $ajax_enabled = $field_settings_helper->ajaxEnabled($entity_type, $bundle, $field_name, $view_mode);
+                if ($ajax_enabled) {
+                    $build[$field_name]['#attributes']['data-ajax_pager'] = $pager_id;
+                    $actual_field_name = $field['#field_name'];
+                    $build[$actual_field_name]['#attached']['library'][] = 'field_longtext_pager/ajax_pager.js';
+                    $ajax_url = \Drupal\Core\Url::fromRoute('field_longtext_pager.ajax_pager.api')->toString();
+                    $build[$actual_field_name]['#attached']['drupalSettings']['ajax_pager'][$pager_id] = [
+                        'ajax_url' => $ajax_url,
+                        'ajax_pager' => [
+                            'pager_id' => $pager_id,
+                            'entity_id' => $entity_id,
+                            'field_name' => $field['#field_name'],
+                            'entity_type' => $field['#entity_type'],
+                            'bundle' => $field['#bundle'],
+                            'view_mode' => $view_mode,
+                        ],
+                    ];
+                }
+            }
+        }
+    }
+}
