diff --git a/node_edit_access_by_term.module b/node_edit_access_by_term.module
index c9c26c9..5da0bf4 100644
--- a/node_edit_access_by_term.module
+++ b/node_edit_access_by_term.module
@@ -4,7 +4,8 @@
  * @file
  * Main module file for node_edit_access_by_term.
  */
-
+use Drupal\Core\Hook\Attribute\LegacyHook;
+use Drupal\node_edit_access_by_term\Hook\NodeEditAccessByTermHooks;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\user\Entity\Role;
@@ -15,114 +16,28 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
 /**
  * Implements hook_form_FORM_ID_alter().
  */
-function node_edit_access_by_term_form_taxonomy_term_form_alter(
-  array &$form,
-  FormStateInterface $form_state,
-  string $form_id,
-): void {
-
-  // Load the term.
-  $term = NULL;
-  $form_object = $form_state->getFormObject();
-  if (method_exists($form_object, 'getEntity')) {
-    $term = $form_object->getEntity();
-  }
-
-  // Get the term id from the term object.
-  $tid = $term->id();
-
-  // Get the selected users and roles if there is a
-  // tid already, present, meaning this is not a new
-  // term.  If there are no users or roles, then have
-  // an empty array.
-  $selected_uids = $tid ? _node_edit_access_by_term_get_ids($tid, 'user') : [];
-  $selected_rids = $tid ? _node_edit_access_by_term_get_ids($tid, 'role') : [];
-
-  // Get the entities for the selected users and roles.
-  $default_uids = _node_edit_access_by_term_get_entities($selected_uids, 'user');
-  $default_rids = _node_edit_access_by_term_get_entities($selected_rids, 'role');
-
-  // Add the fieldset to the form.
-  $form['node_edit_access_wrapper'] = [
-    '#type' => 'fieldset',
-    '#title' => t('Node Edit Access'),
-  ];
-
-  // Add the users field to the form.
-  $form['node_edit_access_wrapper']['node_edit_access_by_term_users'] = [
-    '#type' => 'entity_autocomplete',
-    '#title' => t('Users with node edit access'),
-    '#target_type' => 'user',
-    '#tags' => TRUE,
-    '#default_value' => !empty($default_uids) ? $default_uids : NULL,
-    '#description' => t('Select users who can edit nodes tagged with this term. If both users and roles are blank normal node permissions will apply.'),
-    '#weight' => 0,
-  ];
-
-  // Add the roles field to the form.
-  $form['node_edit_access_wrapper']['node_edit_access_by_term_roles'] = [
-    '#type' => 'entity_autocomplete',
-    '#title' => t('Roles with node edit access'),
-    '#target_type' => 'user_role',
-    '#tags' => TRUE,
-    '#default_value' => !empty($default_rids) ? $default_rids : NULL,
-    '#description' => t('Select roles who can edit nodes tagged with this term. If both users and roles are blank normal node permissions will apply.'),
-    '#weight' => 0,
-  ];
-
-  // Add the submit handler to save the user access.
-  $form['actions']['submit']['#submit'][] = '_node_edit_access_by_term_form_submit';
+#[LegacyHook]
+function node_edit_access_by_term_form_taxonomy_term_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void
+{
+    \Drupal::service(NodeEditAccessByTermHooks::class)->formTaxonomyTermFormAlter($form, $form_state, $form_id);
 }
 
 /**
  * Implements hook_entity_insert().
  */
+#[LegacyHook]
 function node_edit_access_by_term_entity_insert(EntityInterface $entity): void {
 
-  // If this a term, save the user IDs.
-  if ($entity->getEntityTypeId() === 'taxonomy_term') {
-
-    // Get the uids from the entity or a blank array.
-    if (property_exists($entity, 'node_edit_access_by_term_users')) {
-      $uids = $entity->node_edit_access_by_term_users;
-    }
-    else {
-      $uids = [];
-    }
-
-    // Get the rids from the entity or a blank array.
-    if (property_exists($entity, 'node_edit_access_by_term_roles')) {
-      $rids = $entity->node_edit_access_by_term_roles;
-    }
-    else {
-      $rids = [];
-    }
-
-    // Save the uids and rids to the database.
-    _node_edit_access_by_term_save(
-      $entity->id(),
-      $uids,
-      $rids
-    );
-  }
+  \Drupal::service(NodeEditAccessByTermHooks::class)->entityInsert($entity);
 }
 
 /**
  * Implements hook_entity_delete().
  */
+#[LegacyHook]
 function node_edit_access_by_term_entity_delete(EntityInterface $entity): void {
 
-  // If this a term, delete all entries in the database.
-  if ($entity->getEntityTypeId() === 'taxonomy_term') {
-
-    // The database connection.
-    $connection = Database::getConnection();
-
-    // Delete all entries in the table for the term.
-    $connection->delete('node_edit_access_by_term')
-      ->condition('tid', $entity->id())
-      ->execute();
-  }
+  \Drupal::service(NodeEditAccessByTermHooks::class)->entityDelete($entity);
 }
 
 /**
diff --git a/node_edit_access_by_term.services.yml b/node_edit_access_by_term.services.yml
new file mode 100644
index 0000000..dd18568
--- /dev/null
+++ b/node_edit_access_by_term.services.yml
@@ -0,0 +1,5 @@
+
+services:
+  Drupal\node_edit_access_by_term\Hook\NodeEditAccessByTermHooks:
+    class: Drupal\node_edit_access_by_term\Hook\NodeEditAccessByTermHooks
+    autowire: true
diff --git a/src/Hook/NodeEditAccessByTermHooks.php b/src/Hook/NodeEditAccessByTermHooks.php
new file mode 100644
index 0000000..1921349
--- /dev/null
+++ b/src/Hook/NodeEditAccessByTermHooks.php
@@ -0,0 +1,112 @@
+<?php
+
+namespace Drupal\node_edit_access_by_term\Hook;
+
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\user\Entity\Role;
+use Drupal\user\Entity\User;
+use Drupal\Core\Database\Database;
+use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
+use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
+/**
+ * Hook implementations for node_edit_access_by_term.
+ */
+class NodeEditAccessByTermHooks
+{
+    use StringTranslationTrait;
+    /**
+     * Implements hook_form_FORM_ID_alter().
+     */
+    #[Hook('form_taxonomy_term_form_alter')]
+    public function formTaxonomyTermFormAlter(array &$form, \Drupal\Core\Form\FormStateInterface $form_state, string $form_id): void
+    {
+        // Load the term.
+        $term = NULL;
+        $form_object = $form_state->getFormObject();
+        if (method_exists($form_object, 'getEntity')) {
+            $term = $form_object->getEntity();
+        }
+        // Get the term id from the term object.
+        $tid = $term->id();
+        // Get the selected users and roles if there is a
+        // tid already, present, meaning this is not a new
+        // term.  If there are no users or roles, then have
+        // an empty array.
+        $selected_uids = $tid ? _node_edit_access_by_term_get_ids($tid, 'user') : [
+        ];
+        $selected_rids = $tid ? _node_edit_access_by_term_get_ids($tid, 'role') : [
+        ];
+        // Get the entities for the selected users and roles.
+        $default_uids = _node_edit_access_by_term_get_entities($selected_uids, 'user');
+        $default_rids = _node_edit_access_by_term_get_entities($selected_rids, 'role');
+        // Add the fieldset to the form.
+        $form['node_edit_access_wrapper'] = [
+            '#type' => 'fieldset',
+            '#title' => $this->t('Node Edit Access'),
+        ];
+        // Add the users field to the form.
+        $form['node_edit_access_wrapper']['node_edit_access_by_term_users'] = [
+            '#type' => 'entity_autocomplete',
+            '#title' => $this->t('Users with node edit access'),
+            '#target_type' => 'user',
+            '#tags' => TRUE,
+            '#default_value' => !empty($default_uids) ? $default_uids : NULL,
+            '#description' => $this->t('Select users who can edit nodes tagged with this term. If both users and roles are blank normal node permissions will apply.'),
+            '#weight' => 0,
+        ];
+        // Add the roles field to the form.
+        $form['node_edit_access_wrapper']['node_edit_access_by_term_roles'] = [
+            '#type' => 'entity_autocomplete',
+            '#title' => $this->t('Roles with node edit access'),
+            '#target_type' => 'user_role',
+            '#tags' => TRUE,
+            '#default_value' => !empty($default_rids) ? $default_rids : NULL,
+            '#description' => $this->t('Select roles who can edit nodes tagged with this term. If both users and roles are blank normal node permissions will apply.'),
+            '#weight' => 0,
+        ];
+        // Add the submit handler to save the user access.
+        $form['actions']['submit']['#submit'][] = '_node_edit_access_by_term_form_submit';
+    }
+    /**
+     * Implements hook_entity_insert().
+     */
+    #[Hook('entity_insert')]
+    public static function entityInsert(\Drupal\Core\Entity\EntityInterface $entity): void
+    {
+        // If this a term, save the user IDs.
+        if ($entity->getEntityTypeId() === 'taxonomy_term') {
+            // Get the uids from the entity or a blank array.
+            if (property_exists($entity, 'node_edit_access_by_term_users')) {
+                $uids = $entity->node_edit_access_by_term_users;
+            } else {
+                $uids = [
+                ];
+            }
+            // Get the rids from the entity or a blank array.
+            if (property_exists($entity, 'node_edit_access_by_term_roles')) {
+                $rids = $entity->node_edit_access_by_term_roles;
+            } else {
+                $rids = [
+                ];
+            }
+            // Save the uids and rids to the database.
+            _node_edit_access_by_term_save($entity->id(), $uids, $rids);
+        }
+    }
+    /**
+     * Implements hook_entity_delete().
+     */
+    #[Hook('entity_delete')]
+    public static function entityDelete(\Drupal\Core\Entity\EntityInterface $entity): void
+    {
+        // If this a term, delete all entries in the database.
+        if ($entity->getEntityTypeId() === 'taxonomy_term') {
+            // The database connection.
+            $connection = \Drupal\Core\Database\Database::getConnection();
+            // Delete all entries in the table for the term.
+            $connection->delete('node_edit_access_by_term')->condition('tid', $entity->id())->execute();
+        }
+    }
+}
