diff --git a/src/Hook/TaxonomyReplaceHooks.php b/src/Hook/TaxonomyReplaceHooks.php
new file mode 100644
index 0000000..f613a3e
--- /dev/null
+++ b/src/Hook/TaxonomyReplaceHooks.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Drupal\taxonomy_replace\Hook;
+
+use Drupal\Core\Access\AccessResult;
+use Drupal\taxonomy\TermInterface;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
+/**
+ * Hook implementations for taxonomy_replace.
+ */
+class TaxonomyReplaceHooks
+{
+    use StringTranslationTrait;
+    /**
+     * Implements hook_entity_type_build().
+     */
+    #[Hook('entity_type_build')]
+    public static function entityTypeBuild(array &$entity_types)
+    {
+        // Add a custom entity form and link template.
+        $entity_types['taxonomy_term']->setFormClass('replace', '\Drupal\taxonomy_replace\Form\TaxonomyReplaceForm');
+        $entity_types['taxonomy_term']->setLinkTemplate('replace', '/taxonomy/term/{taxonomy_term}/replace');
+    }
+    /**
+     * Implements hook_entity_operation().
+     */
+    #[Hook('entity_operation')]
+    public function entityOperation(\Drupal\Core\Entity\EntityInterface $entity)
+    {
+        $operations = [
+        ];
+        if ($entity instanceof \Drupal\taxonomy\TermInterface) {
+            $account = \Drupal::currentUser();
+            $access_result = \Drupal\Core\Access\AccessResult::allowedIfHasPermission($account, 'replace taxonomy terms')->andIf($entity->access('delete', $account, TRUE));
+            if ($access_result->isAllowed()) {
+                $destination = \Drupal::destination();
+                $operations['replace'] = [
+                    'title' => $this->t('Replace'),
+                    'url' => $entity->toUrl('replace')->mergeOptions([
+                        'query' => $destination->getAsArray(),
+                    ]),
+                    'weight' => 99,
+                ];
+            }
+        }
+        return $operations;
+    }
+}
diff --git a/taxonomy_replace.module b/taxonomy_replace.module
index ef9d23c..c110f3d 100644
--- a/taxonomy_replace.module
+++ b/taxonomy_replace.module
@@ -4,7 +4,8 @@
  * @file
  * Hook implementations for taxonomy_replace.
  */
-
+use Drupal\Core\Hook\Attribute\LegacyHook;
+use Drupal\taxonomy_replace\Hook\TaxonomyReplaceHooks;
 use Drupal\Core\Access\AccessResult;
 use Drupal\taxonomy\TermInterface;
 use Drupal\Core\Entity\EntityInterface;
@@ -12,33 +13,17 @@ use Drupal\Core\Entity\EntityInterface;
 /**
  * Implements hook_entity_type_build().
  */
-function taxonomy_replace_entity_type_build(array &$entity_types) {
-  // Add a custom entity form and link template.
-  $entity_types['taxonomy_term']->setFormClass('replace', '\Drupal\taxonomy_replace\Form\TaxonomyReplaceForm');
-  $entity_types['taxonomy_term']->setLinkTemplate('replace', '/taxonomy/term/{taxonomy_term}/replace');
+#[LegacyHook]
+function taxonomy_replace_entity_type_build(array &$entity_types)
+{
+    \Drupal::service(TaxonomyReplaceHooks::class)->entityTypeBuild($entity_types);
 }
 
 /**
  * Implements hook_entity_operation().
  */
-function taxonomy_replace_entity_operation(EntityInterface $entity) {
-  $operations = [];
-  if ($entity instanceof TermInterface) {
-    $account = \Drupal::currentUser();
-    $access_result = AccessResult::allowedIfHasPermission($account, 'replace taxonomy terms')
-      ->andIf($entity->access('delete', $account, TRUE));
-
-    if ($access_result->isAllowed()) {
-      $destination = \Drupal::destination();
-      $operations['replace'] = [
-        'title' => t('Replace'),
-        'url' => $entity->toUrl('replace')->mergeOptions(
-          ['query' => $destination->getAsArray()]
-        ),
-        'weight' => 99,
-      ];
-    }
-  }
-
-  return $operations;
+#[LegacyHook]
+function taxonomy_replace_entity_operation(EntityInterface $entity)
+{
+    return \Drupal::service(TaxonomyReplaceHooks::class)->entityOperation($entity);
 }
diff --git a/taxonomy_replace.services.yml b/taxonomy_replace.services.yml
index 6420f54..9c88099 100644
--- a/taxonomy_replace.services.yml
+++ b/taxonomy_replace.services.yml
@@ -2,3 +2,7 @@ services:
   taxonomy_replace.replacer:
     class: Drupal\taxonomy_replace\Service\TaxonomyReplaceService
     arguments: ['@entity_type.manager', '@database']
+
+  Drupal\taxonomy_replace\Hook\TaxonomyReplaceHooks:
+    class: Drupal\taxonomy_replace\Hook\TaxonomyReplaceHooks
+    autowire: true
