diff --git a/scan_code.module b/scan_code.module
index 8cac949..924def6 100644
--- a/scan_code.module
+++ b/scan_code.module
@@ -4,7 +4,9 @@
  * @file
  * Scan code module file.
  */
-
+use Drupal\Core\Hook\Attribute\LegacyHook;
+use Drupal\scan_code\Hook\ScanCodeHooks;
+use Drupal\Component\Utility\DeprecationHelper;
 use Drupal\Core\Field\FieldDefinitionInterface;
 use Drupal\Core\Field\PluginSettingsBase;
 use Drupal\Core\Field\WidgetInterface;
@@ -29,7 +31,15 @@ function scan_code_field_widget_third_party_settings_form(
   if (in_array($plugin->getPluginId(), $scan_code_settings->getWidgetsArray())) {
 
     // Scan code group.
-    $element['scan_code_group'] = [
+    $element['scan_code_group'] = DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '11.2.0', fn() => [
+      '#type' => 'fieldset',
+      '#title' => t('Scan Code'),
+      '#attributes' => [
+        'class' => [
+          'scan-code-fieldgroup',
+        ],
+      ],
+    ], fn() => [
       '#type' => 'fieldgroup',
       '#title' => t('Scan Code'),
       '#attributes' => [
@@ -37,7 +47,7 @@ function scan_code_field_widget_third_party_settings_form(
           'scan-code-fieldgroup',
         ],
       ],
-    ];
+    ]);
 
     $scan_code_group = $plugin->getThirdPartySetting('scan_code', 'scan_code_group');
     $element['scan_code_group']['barcode_scan_enabled'] = [
@@ -76,55 +86,12 @@ function scan_code_field_widget_third_party_settings_form(
 /**
  * Implements hook_code_field_widget_single_element_form_alter().
  */
+#[LegacyHook]
 function scan_code_field_widget_single_element_form_alter(
   array &$element,
   FormStateInterface $form_state,
   array $context,
 ) {
 
-  if ($context['widget'] instanceof PluginSettingsBase
-  && $settings = $context['widget']->getThirdPartySettings('scan_code')) {
-
-    $module_path = \Drupal::service('extension.list.module')->getPath('scan_code');
-
-    // Add Barcode button.
-    $element['scan_code_barcode'] = [
-      '#type' => 'html_tag',
-      '#tag' => 'img',
-      '#weight' => 1,
-      '#attributes' => [
-        'class' => [
-          'scan-code-toggle',
-        ],
-        'src' => "/$module_path/images/barcode-scan-icon.svg",
-      ],
-      '#attached' => [
-        'library' => [
-          'scan_code/quagga',
-          'scan_code/webrtc',
-          'scan_code/scancode_library',
-        ],
-      ],
-    ];
-
-    if (isset($settings['scan_code_group']['scan_code_patterns'])) {
-      $patterns = [];
-      foreach ($settings['scan_code_group']['scan_code_patterns'] as $pattern) {
-        if ($pattern !== 0) {
-          $patterns[] = $pattern;
-        }
-      }
-    }
-
-    // Drupal settings for JS.
-    $config = \Drupal::configFactory()->getEditable('scan_code.settings');
-    $element['#attached']['drupalSettings']['scan_code'] = [
-      'statusOnLoad' => $config->get('status_on_load'),
-      'closeAfterScanning' => $config->get('close_after_scanning'),
-      'delay' => $config->get('delay'),
-      'textBarcodeReading' => $config->get('text_barcode_reading'),
-      'patterns' => $patterns,
-    ];
-
-  }
+  \Drupal::service(ScanCodeHooks::class)->fieldWidgetSingleElementFormAlter($element, $form_state, $context);
 }
diff --git a/scan_code.services.yml b/scan_code.services.yml
index de46cee..39d06ac 100644
--- a/scan_code.services.yml
+++ b/scan_code.services.yml
@@ -2,3 +2,7 @@ services:
   scan_code.settings:
     class: Drupal\scan_code\Services\ScanCodeSettings
     arguments: ['@config.factory']
+
+  Drupal\scan_code\Hook\ScanCodeHooks:
+    class: Drupal\scan_code\Hook\ScanCodeHooks
+    autowire: true
diff --git a/src/Hook/ScanCodeHooks.php b/src/Hook/ScanCodeHooks.php
new file mode 100644
index 0000000..696f757
--- /dev/null
+++ b/src/Hook/ScanCodeHooks.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace Drupal\scan_code\Hook;
+
+use Drupal\Component\Utility\DeprecationHelper;
+use Drupal\Core\Field\FieldDefinitionInterface;
+use Drupal\Core\Field\PluginSettingsBase;
+use Drupal\Core\Field\WidgetInterface;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Hook\Attribute\Hook;
+/**
+ * Hook implementations for scan_code.
+ */
+class ScanCodeHooks
+{
+    /**
+     * Implements hook_code_field_widget_single_element_form_alter().
+     */
+    #[Hook('code_field_widget_single_element_form_alter', module: 'scan')]
+    public function fieldWidgetSingleElementFormAlter(array &$element, \Drupal\Core\Form\FormStateInterface $form_state, array $context)
+    {
+        if ($context['widget'] instanceof \Drupal\Core\Field\PluginSettingsBase && $settings = $context['widget']->getThirdPartySettings('scan_code')) {
+            $module_path = \Drupal::service('extension.list.module')->getPath('scan_code');
+            // Add Barcode button.
+            $element['scan_code_barcode'] = [
+                '#type' => 'html_tag',
+                '#tag' => 'img',
+                '#weight' => 1,
+                '#attributes' => [
+                    'class' => [
+                        'scan-code-toggle',
+                    ],
+                    'src' => "/{$module_path}/images/barcode-scan-icon.svg",
+                ],
+                '#attached' => [
+                    'library' => [
+                        'scan_code/quagga',
+                        'scan_code/webrtc',
+                        'scan_code/scancode_library',
+                    ],
+                ],
+            ];
+            if (isset($settings['scan_code_group']['scan_code_patterns'])) {
+                $patterns = [
+                ];
+                foreach ($settings['scan_code_group']['scan_code_patterns'] as $pattern) {
+                    if ($pattern !== 0) {
+                        $patterns[] = $pattern;
+                    }
+                }
+            }
+            // Drupal settings for JS.
+            $config = \Drupal::configFactory()->getEditable('scan_code.settings');
+            $element['#attached']['drupalSettings']['scan_code'] = [
+                'statusOnLoad' => $config->get('status_on_load'),
+                'closeAfterScanning' => $config->get('close_after_scanning'),
+                'delay' => $config->get('delay'),
+                'textBarcodeReading' => $config->get('text_barcode_reading'),
+                'patterns' => $patterns,
+            ];
+        }
+    }
+}
diff --git a/tests/src/Functional/ScanCodeTest.php b/tests/src/Functional/ScanCodeTest.php
index 094507b..2bbfbbd 100644
--- a/tests/src/Functional/ScanCodeTest.php
+++ b/tests/src/Functional/ScanCodeTest.php
@@ -2,6 +2,8 @@
 
 namespace Drupal\Tests\scan_code\Functional;
 
+use PHPUnit\Framework\Attributes\Group;
+use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
 use Drupal\Tests\BrowserTestBase;
 
 /**
@@ -9,6 +11,8 @@ use Drupal\Tests\BrowserTestBase;
  *
  * @group scan_code
  */
+#[Group('scan_code')]
+#[RunTestsInSeparateProcesses]
 class ScanCodeTest extends BrowserTestBase {
 
   /**
diff --git a/tests/src/Kernel/AddScanCodeFormPluginTest.php b/tests/src/Kernel/AddScanCodeFormPluginTest.php
index 75850b3..d4b332f 100644
--- a/tests/src/Kernel/AddScanCodeFormPluginTest.php
+++ b/tests/src/Kernel/AddScanCodeFormPluginTest.php
@@ -2,6 +2,8 @@
 
 namespace Drupal\Tests\scan_code\Kernel;
 
+use PHPUnit\Framework\Attributes\Group;
+use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
 use Drupal\Core\Entity\Entity\EntityFormDisplay;
 use Drupal\Core\Field\FieldStorageDefinitionInterface;
 use Drupal\field\Entity\FieldConfig;
@@ -14,6 +16,8 @@ use Drupal\node\Entity\NodeType;
  *
  * @group scan_code
  */
+#[Group('scan_code')]
+#[RunTestsInSeparateProcesses]
 class AddScanCodeFormPluginTest extends KernelTestBase {
 
   /**
