diff --git a/multiple_registration.info.yml b/multiple_registration.info.yml
index 5b5ae70..7d1df5c 100644
--- a/multiple_registration.info.yml
+++ b/multiple_registration.info.yml
@@ -1,7 +1,7 @@
 name: Multiple Registration
 type: module
 description: Adds ability to create several registration pages
-core_version_requirement: ^10 || ^11
+core_version_requirement: ^11.2 || ^12
 package: Other
 configure: multiple_registration.multiple_registration_list_index
 dependencies:
diff --git a/multiple_registration.module b/multiple_registration.module
index ace7e6d..34600b9 100755
--- a/multiple_registration.module
+++ b/multiple_registration.module
@@ -4,7 +4,8 @@
  * @file
  * Contains multiple_registration.module.
  */
-
+use Drupal\Core\Hook\Attribute\LegacyHook;
+use Drupal\multiple_registration\Hook\MultipleRegistrationHooks;
 use Drupal\Core\Block\BlockPluginInterface;
 use Drupal\Core\Config\Entity\ThirdPartySettingsInterface;
 use Drupal\Core\Database\Database;
@@ -24,105 +25,43 @@ use Drupal\views\ViewExecutable;
 /**
  * Implements hook_help().
  */
+#[LegacyHook]
 function multiple_registration_help($route_name, RouteMatchInterface $route_match) {
-  switch ($route_name) {
-    // Main module help for the multiple_registration module.
-    case 'help.page.multiple_registration':
-      $path = dirname(__FILE__) . '/README.txt';
-      if (file_exists($path)) {
-        $readme = file_get_contents($path);
-      }
-
-      if (!isset($readme)) {
-        return NULL;
-      }
-
-      return '<pre>' . $readme . '</pre>';
-  }
+  return \Drupal::service(MultipleRegistrationHooks::class)->help($route_name, $route_match);
 }
 
 /**
  * Implements hook_theme().
  */
-function multiple_registration_theme() {
-  $theme = [];
-  return $theme;
+#[LegacyHook]
+function multiple_registration_theme()
+{
+    return \Drupal::service(MultipleRegistrationHooks::class)->theme();
 }
 
 /**
  * Implements hook_permission().
  */
+#[LegacyHook]
 function multiple_registration_permission() {
-  return [
-    'administer multiple_registration' => [
-      'title' => t('Administer multiple registration'),
-      'description' => t('Configure multiple registration module'),
-    ],
-  ];
+  return \Drupal::service(MultipleRegistrationHooks::class)->permission();
 }
 
 /**
  * Implements hook_entity_operation_alter().
  */
+#[LegacyHook]
 function multiple_registration_entity_operation_alter(array &$operations, EntityInterface $entity) {
-  if ($entity->getEntityTypeId() === 'user_role') {
-    if (\Drupal::service('router.route_provider')->getRouteByName('multiple_registration.create_registration_page_form')) {
-      $available_roles = \Drupal::service('multiple_registration.service')->getAvailableRoles();
-      if (!array_key_exists($entity->id(), $available_roles)) {
-        return;
-      }
-      $operations['add_registration_page'] = [
-        'title' => t('Add own registration page'),
-        'url' => Url::fromRoute('multiple_registration.create_registration_page_form', ['rid' => $entity->id()]),
-        'weight' => 50,
-      ];
-    }
-  }
+  \Drupal::service(MultipleRegistrationHooks::class)->entityOperationAlter($operations, $entity);
 }
 
 /**
  * Implements hook_form_FORM_ID_alter().
  */
-function multiple_registration_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
-  /** @var \Drupal\Core\Entity\EntityFormInterface $field_object */
-  $field_object = $form_state->getFormObject();
-  /** @var \Drupal\field\Entity\FieldConfig $instance */
-  $instance = $field_object->getEntity();
-  if ($instance->get('entity_type') === 'user' && !$instance->isDeleted() && !$instance->isReadonly()) {
-
-    $reg_pages = \Drupal::service('multiple_registration.service')->getRegistrationPages();
-    if ($reg_pages) {
-      $options[MultipleRegistrationController::MULTIPLE_REGISTRATION_GENERAL_REGISTRATION_ID] = t('General registered users');
-      foreach ($reg_pages as $rid => $page) {
-        $options[$rid] = t('Users with %role role', ['%role' => $page['role_name']]);
-      }
-      $descr = t('Specify which of options are actual for this field. If nothing is selected, field is available for all variants.');
-      $def_val = $instance->getThirdPartySetting('multiple_registration', 'user_additional_register_form', []);
-
-      $form['field']['third_party_settings']['multiple_registration'] = [
-        '#type' => 'checkboxes',
-        '#title' => t('This field is needed for:'),
-        '#description' => $descr,
-        '#default_value' => $def_val,
-        '#options' => $options,
-      ];
-
-      if (!isset($form['required']['#default_value']) || !$form['required']['#default_value']) {
-        $descr = t('Note: works only if "Required field" is unchecked!');
-        $def_val = $instance->getThirdPartySetting('multiple_registration', 'user_additional_register_form_required', []);
-
-        $form['field']['third_party_settings']['multiple_registration_required'] = [
-          '#type' => 'checkboxes',
-          '#title' => t('This field is required for:'),
-          '#description' => $descr,
-          '#default_value' => $def_val,
-          '#options' => $options,
-        ];
-      }
-
-      $form['actions']['submit']['#submit'][] = 'multiple_registration_field_config_form_submit';
-    }
-  }
+#[LegacyHook]
+function multiple_registration_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id)
+{
+    \Drupal::service(MultipleRegistrationHooks::class)->formFieldConfigEditFormAlter($form, $form_state, $form_id);
 }
 
 /**
@@ -186,44 +125,10 @@ function multiple_registration_field_config_form_submit(array &$form, FormStateI
 /**
  * Implements hook_form_alter().
  */
-function multiple_registration_form_alter(&$form, FormStateInterface $form_state, $form_id) {
-  $storage = $form_state->getStorage();
-  if (!empty($storage['form_display']) && is_object($storage['form_display'])) {
-    $form_display = $storage['form_display'];
-    if ($form_display instanceof EntityFormDisplay && $form_display->getTargetEntityTypeId() === 'user') {
-      // Show only appropriate fields.
-      $field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('user', 'user');
-      foreach ($field_definitions as $field_name => $field_definition) {
-        if (isset($form[$field_name]) && $field_definition instanceof ThirdPartySettingsInterface) {
-          $field_roles = array_filter($field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form', []));
-          $field_roles_required = array_filter($field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form_required', []));
-          if (!empty($field_roles)) {
-            // If something was selected.
-            if ($form[$field_name]['#access'] !== false) {
-              $form[$field_name]['#access'] = MultipleRegistrationController::checkFieldAccess($field_roles);
-              $form[$field_name]['widget']['#required'] = MultipleRegistrationController::checkFieldAccess($field_roles_required);
-            }
-          }
-        }
-      }
-    }
-  }
-
-  $route_match = \Drupal::routeMatch();
-  $route = $route_match->getRouteObject();
-  $route_name = $route_match->getRouteName();
-  if ($route !== NULL && $route_name === 'multiple_registration.role_registration_page' && $form_id === 'user_register_form') {
-    $rid = \Drupal::routeMatch()->getParameter('rid');
-
-    // Hidden field to pass the rid.
-    $form['multiple_registration_rid'] = [
-      '#type' => 'hidden',
-      '#value' => $rid,
-    ];
-
-    // Custom submit handler to store the rid.
-    $form['actions']['submit']['#submit'][] = '_multiple_registration_rid';
-  }
+#[LegacyHook]
+function multiple_registration_form_alter(&$form, FormStateInterface $form_state, $form_id)
+{
+    \Drupal::service(MultipleRegistrationHooks::class)->formAlter($form, $form_state, $form_id);
 }
 
 /**
@@ -255,80 +160,19 @@ function _multiple_registration_rid(array $form, FormStateInterface $form_state)
 /**
  * Implements hook_field_widget_single_element_form_alter().
  */
-function multiple_registration_field_widget_single_element_form_alter(array &$element, FormStateInterface $form_state, array $context) {
-  $field_definition = $context['items']->getFieldDefinition();
-  $field_name = $field_definition->getName();
-  $parents = $context['form']['#parents'];
-  $widget_state = WidgetBase::getWidgetState($parents, $field_name, $form_state);
-  if ($field_definition->getTargetEntityTypeId() === 'user' && $field_definition instanceof ThirdPartySettingsInterface) {
-    if ($field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form')) {
-      $field_roles = $field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form');
-    }
-    else {
-      $field_roles = [];
-    }
-    if ($field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form_required')) {
-      $field_roles_required = $field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form_required');
-    }
-    else {
-      $field_roles_required = [];
-    }
-
-    // Conditions for AJAX triggers and paragraphs with removed states.
-    $has_not_triggering_elements = $form_state->getTriggeringElement() === NULL;
-    $paragraphs_with_removed_mode = (!isset($form_state->getTriggeringElement()['#paragraphs_mode']) && (isset($form_state->getTriggeringElement()['#paragraphs_mode']) && $form_state->getTriggeringElement()['#paragraphs_mode'] !== 'removed'));
-
-    // If something was selected.
-    if (!empty($field_roles) && max($field_roles) !== 0) {
-      if ($has_not_triggering_elements || $paragraphs_with_removed_mode) {
-        $element['#access'] = MultipleRegistrationController::checkFieldAccess($field_roles);
-      }
-    }
-    if ((!isset($element['#required']) || $element['#required'] === FALSE) && !empty($field_roles_required)) {
-      // If something was selected.
-      if (max($field_roles_required) !== 0) {
-        $required = MultipleRegistrationController::checkFieldAccess($field_roles_required);
-        $element['#required'] = $required;
-        // Fix 'N/A' element option for 'required' widgets to make them
-        // similar with core widgets behaviour.
-        if (isset($element['#options']['_none'])) {
-          if ($element['#type'] === 'radios' || $element['#type'] === 'checkboxes') {
-            unset($element['#options']['_none']);
-          }
-          if ($element['#type'] === 'select') {
-            $element['#options']['_none'] = \Drupal::translation()->translate('- Select a value -');
-          }
-        }
-        foreach (Element::children($element) as $child) {
-          if ($widget_state['items_count'] === 0 || (isset($element[$child]['#delta']) && $element[$child]['#delta'] < $widget_state['items_count'])) {
-            $element[$child]['#required'] = $required;
-          }
-        }
-      }
-    }
-  }
+#[LegacyHook]
+function multiple_registration_field_widget_single_element_form_alter(array &$element, FormStateInterface $form_state, array $context)
+{
+    \Drupal::service(MultipleRegistrationHooks::class)->fieldWidgetSingleElementFormAlter($element, $form_state, $context);
 }
 
 /**
  * Implements hook_form_FORM_ID_alter().
  */
-function multiple_registration_form_user_register_form_alter(&$form, FormStateInterface $form_state, $form_id) {
-  $route_match = \Drupal::routeMatch();
-  $route = $route_match->getRouteName();
-  $current_user = \Drupal::currentUser();
-  if ($route === 'multiple_registration.role_registration_page') {
-
-    // Redirect authenticated user to user profile page instead of reg. form.
-    if ($current_user->isAuthenticated()) {
-      \Drupal::service('multiple_registration.controller_service')->authenticatedUserRedirect($current_user);
-    }
-
-    $rid = $route_match->getParameter('rid');
-
-    // Adding role id to the form array.
-    $form['rid'] = ['#type' => 'value', '#value' => $rid];
-    $form['#validate'][] = 'multiple_registration_user_register_form_validate';
-  }
+#[LegacyHook]
+function multiple_registration_form_user_register_form_alter(&$form, FormStateInterface $form_state, $form_id)
+{
+    \Drupal::service(MultipleRegistrationHooks::class)->formUserRegisterFormAlter($form, $form_state, $form_id);
 }
 
 /**
@@ -343,18 +187,9 @@ function multiple_registration_user_register_form_validate(array &$form, FormSta
 /**
  * Implements hook_block_view_BASE_BLOCK_ID_alter().
  */
+#[LegacyHook]
 function multiple_registration_block_view_user_login_block_alter(array &$build, BlockPluginInterface $block) {
-  if (isset($build['content']['user_links'])) {
-    if (\Drupal::config('user.settings')->get('register') !== UserInterface::REGISTER_ADMINISTRATORS_ONLY) {
-      $reg_pages = \Drupal::service('multiple_registration.service')->getRegistrationPages();
-      foreach ($reg_pages as $rid => $role) {
-        $uri = 'base:' . $role['url'];
-        $reg_url = Url::fromUri($uri);
-        $reg_link = Link::fromTextAndUrl(t('Create new @role account', ['@role' => $role['role_name']]), $reg_url);
-        $build['content']['user_links']['#items']['multiple_registration_' . $rid] = $reg_link;
-      }
-    }
-  }
+  \Drupal::service(MultipleRegistrationHooks::class)->blockViewUserLoginBlockAlter($build, $block);
 }
 
 /**
@@ -418,25 +253,17 @@ function multiple_registration_entity_form_display_alter(EntityFormDisplayInterf
 /**
  * Implements hook_ENTITY_TYPE_insert().
  */
+#[LegacyHook]
 function multiple_registration_user_insert(EntityInterface $entity) {
-  try {
-    multiple_registration_handle_user_entity($entity);
-  }
-  catch (\Exception $exception) {
-    \Drupal::logger('multiple_registration')->notice($exception->getMessage());
-  }
+  \Drupal::service(MultipleRegistrationHooks::class)->userInsert($entity);
 }
 
 /**
  * Implements hook_ENTITY_TYPE_presave().
  */
+#[LegacyHook]
 function multiple_registration_user_presave(EntityInterface $entity) {
-  try {
-    multiple_registration_handle_user_entity($entity);
-  }
-  catch (\Exception $exception) {
-    \Drupal::logger('multiple_registration')->notice($exception->getMessage());
-  }
+  \Drupal::service(MultipleRegistrationHooks::class)->userPresave($entity);
 }
 
 /**
@@ -541,35 +368,8 @@ function multiple_registration_update_registration_table($user_id, $role_id, $re
 /**
  * Implements hook_views_pre_view().
  */
-function multiple_registration_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
-  $enable_buttons = \Drupal::config('multiple_registration.common_settings_page_form_config')->get('enable_add_user_buttons_on_people_page');
-
-  if (!$enable_buttons) {
-    return;
-  }
-
-  if ($view->id() == 'user_admin_people' && $display_id === 'page_1') {
-    $result = [];
-    $service = \Drupal::service('multiple_registration.service');
-    $available_roles = $service->getRegistrationPages();
-
-    foreach ($available_roles as $role) {
-      $link_label = t('Add new @role', ['@role' => $role['role_name']], ['context' => 'multiple_registration']);
-      $result[] = '<a class="button button-action button--primary button--small" href="' . $role["url"] . '">' . $link_label . '</a>';
-    }
-
-    $options = [
-      'id' => 'add_new_user_buttons',
-      'table' => 'views',
-      'field' => 'area_text_custom',
-      'relationship' => 'none',
-      'group_type' => 'none',
-      'admin_label' => '',
-      'empty' => TRUE,
-      'tokenize' => FALSE,
-      'content' => implode($result),
-      'plugin_id' => 'text_custom',
-    ];
-    $view->setHandler('page_1', 'header', 'add_new_user_buttons', $options);
-  }
+#[LegacyHook]
+function multiple_registration_views_pre_view(ViewExecutable $view, $display_id, array &$args)
+{
+    \Drupal::service(MultipleRegistrationHooks::class)->viewsPreView($view, $display_id, $args);
 }
diff --git a/multiple_registration.services.yml b/multiple_registration.services.yml
index 15cc82c..26cdb91 100644
--- a/multiple_registration.services.yml
+++ b/multiple_registration.services.yml
@@ -13,3 +13,7 @@ services:
     arguments: ['@config.factory']
     tags:
           - { name: event_subscriber }
+
+  Drupal\multiple_registration\Hook\MultipleRegistrationHooks:
+    class: Drupal\multiple_registration\Hook\MultipleRegistrationHooks
+    autowire: true
diff --git a/src/Form/AccessSettingsPageForm.php b/src/Form/AccessSettingsPageForm.php
index dd2ea59..52d6c6f 100644
--- a/src/Form/AccessSettingsPageForm.php
+++ b/src/Form/AccessSettingsPageForm.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\multiple_registration\Form;
 
+use Drupal\Component\Utility\DeprecationHelper;
 use Drupal\Core\Cache\CacheBackendInterface;
 use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\Config\TypedConfigManagerInterface;
@@ -150,7 +151,7 @@ class AccessSettingsPageForm extends ConfigFormBase {
           ->set('multiple_registration_pages_allowed_list', $allowed_list)
           ->save();
         $this->routeBuilder->rebuild();
-        $this->cacheRender->invalidateAll();
+        DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '11.2.0', fn() => $this->cacheRender->deleteAll(), fn() => $this->cacheRender->invalidateAll());
         break;
     }
     $form_state->setRedirect('multiple_registration.multiple_registration_list_index');
diff --git a/src/Form/CommonSettingsPageForm.php b/src/Form/CommonSettingsPageForm.php
index ed876e5..fc476c9 100644
--- a/src/Form/CommonSettingsPageForm.php
+++ b/src/Form/CommonSettingsPageForm.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\multiple_registration\Form;
 
+use Drupal\Component\Utility\DeprecationHelper;
 use Drupal\Core\Cache\CacheBackendInterface;
 use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\Config\TypedConfigManagerInterface;
@@ -157,7 +158,7 @@ class CommonSettingsPageForm extends ConfigFormBase {
           ->set('enable_add_user_buttons_on_people_page', $form_state->getValue('enable_add_user_buttons_on_people_page'))
           ->save();
         $this->routeBuilder->rebuild();
-        $this->cacheRender->invalidateAll();
+        DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '11.2.0', fn() => $this->cacheRender->deleteAll(), fn() => $this->cacheRender->invalidateAll());
         break;
     }
     $form_state->setRedirect('multiple_registration.multiple_registration_list_index');
diff --git a/src/Form/CreateRegistrationPageForm.php b/src/Form/CreateRegistrationPageForm.php
index e3aac70..6938c0e 100644
--- a/src/Form/CreateRegistrationPageForm.php
+++ b/src/Form/CreateRegistrationPageForm.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\multiple_registration\Form;
 
+use Drupal\Component\Utility\DeprecationHelper;
 use Drupal\Core\Cache\CacheBackendInterface;
 use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\Config\TypedConfigManagerInterface;
@@ -204,7 +205,7 @@ class CreateRegistrationPageForm extends ConfigFormBase {
       ->save();
     $this->multipleRegistrationController->addRegisterPageAlias($source, $alias);
     $this->routeBuilder->rebuild();
-    $this->cacheRender->invalidateAll();
+    DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '11.2.0', fn() => $this->cacheRender->deleteAll(), fn() => $this->cacheRender->invalidateAll());
     $form_state->setRedirect('multiple_registration.multiple_registration_list_index');
   }
 
diff --git a/src/Hook/MultipleRegistrationHooks.php b/src/Hook/MultipleRegistrationHooks.php
new file mode 100644
index 0000000..fcdbf85
--- /dev/null
+++ b/src/Hook/MultipleRegistrationHooks.php
@@ -0,0 +1,341 @@
+<?php
+
+namespace Drupal\multiple_registration\Hook;
+
+use Drupal\Core\Block\BlockPluginInterface;
+use Drupal\Core\Config\Entity\ThirdPartySettingsInterface;
+use Drupal\Core\Database\Database;
+use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
+use Drupal\Core\Entity\Entity\EntityFormDisplay;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Field\WidgetBase;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Link;
+use Drupal\Core\Render\Element;
+use Drupal\Core\Routing\RouteMatchInterface;
+use Drupal\Core\Url;
+use Drupal\multiple_registration\Controller\MultipleRegistrationController;
+use Drupal\user\UserInterface;
+use Drupal\views\ViewExecutable;
+use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
+/**
+ * Hook implementations for multiple_registration.
+ */
+class MultipleRegistrationHooks
+{
+    use StringTranslationTrait;
+    /**
+     * Implements hook_help().
+     */
+    #[Hook('help')]
+    public static function help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match)
+    {
+        switch ($route_name) {
+            // Main module help for the multiple_registration module.
+            case 'help.page.multiple_registration':
+                $path = dirname(__FILE__) . '/README.txt';
+                if (file_exists($path)) {
+                    $readme = file_get_contents($path);
+                }
+                if (!isset($readme)) {
+                    return NULL;
+                }
+                return '<pre>' . $readme . '</pre>';
+        }
+    }
+    /**
+     * Implements hook_theme().
+     */
+    #[Hook('theme')]
+    public static function theme()
+    {
+        $theme = [
+        ];
+        return $theme;
+    }
+    /**
+     * Implements hook_permission().
+     */
+    #[Hook('permission')]
+    public function permission()
+    {
+        return [
+            'administer multiple_registration' => [
+                'title' => $this->t('Administer multiple registration'),
+                'description' => $this->t('Configure multiple registration module'),
+            ],
+        ];
+    }
+    /**
+     * Implements hook_entity_operation_alter().
+     */
+    #[Hook('entity_operation_alter')]
+    public function entityOperationAlter(array &$operations, \Drupal\Core\Entity\EntityInterface $entity)
+    {
+        if ($entity->getEntityTypeId() === 'user_role') {
+            if (\Drupal::service('router.route_provider')->getRouteByName('multiple_registration.create_registration_page_form')) {
+                $available_roles = \Drupal::service('multiple_registration.service')->getAvailableRoles();
+                if (!array_key_exists($entity->id(), $available_roles)) {
+                    return;
+                }
+                $operations['add_registration_page'] = [
+                    'title' => $this->t('Add own registration page'),
+                    'url' => \Drupal\Core\Url::fromRoute('multiple_registration.create_registration_page_form', [
+                        'rid' => $entity->id(),
+                    ]),
+                    'weight' => 50,
+                ];
+            }
+        }
+    }
+    /**
+     * Implements hook_form_FORM_ID_alter().
+     */
+    #[Hook('form_field_config_edit_form_alter')]
+    public function formFieldConfigEditFormAlter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
+    {
+        /** @var \Drupal\Core\Entity\EntityFormInterface $field_object */
+        $field_object = $form_state->getFormObject();
+        /** @var \Drupal\field\Entity\FieldConfig $instance */
+        $instance = $field_object->getEntity();
+        if ($instance->get('entity_type') === 'user' && !$instance->isDeleted() && !$instance->isReadonly()) {
+            $reg_pages = \Drupal::service('multiple_registration.service')->getRegistrationPages();
+            if ($reg_pages) {
+                $options[\Drupal\multiple_registration\Controller\MultipleRegistrationController::MULTIPLE_REGISTRATION_GENERAL_REGISTRATION_ID] = $this->t('General registered users');
+                foreach ($reg_pages as $rid => $page) {
+                    $options[$rid] = $this->t('Users with %role role', [
+                        '%role' => $page['role_name'],
+                    ]);
+                }
+                $descr = $this->t('Specify which of options are actual for this field. If nothing is selected, field is available for all variants.');
+                $def_val = $instance->getThirdPartySetting('multiple_registration', 'user_additional_register_form', [
+                ]);
+                $form['field']['third_party_settings']['multiple_registration'] = [
+                    '#type' => 'checkboxes',
+                    '#title' => $this->t('This field is needed for:'),
+                    '#description' => $descr,
+                    '#default_value' => $def_val,
+                    '#options' => $options,
+                ];
+                if (!isset($form['required']['#default_value']) || !$form['required']['#default_value']) {
+                    $descr = $this->t('Note: works only if "Required field" is unchecked!');
+                    $def_val = $instance->getThirdPartySetting('multiple_registration', 'user_additional_register_form_required', [
+                    ]);
+                    $form['field']['third_party_settings']['multiple_registration_required'] = [
+                        '#type' => 'checkboxes',
+                        '#title' => $this->t('This field is required for:'),
+                        '#description' => $descr,
+                        '#default_value' => $def_val,
+                        '#options' => $options,
+                    ];
+                }
+                $form['actions']['submit']['#submit'][] = 'multiple_registration_field_config_form_submit';
+            }
+        }
+    }
+    /**
+     * Implements hook_form_alter().
+     */
+    #[Hook('form_alter')]
+    public static function formAlter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
+    {
+        $storage = $form_state->getStorage();
+        if (!empty($storage['form_display']) && is_object($storage['form_display'])) {
+            $form_display = $storage['form_display'];
+            if ($form_display instanceof \Drupal\Core\Entity\Entity\EntityFormDisplay && $form_display->getTargetEntityTypeId() === 'user') {
+                // Show only appropriate fields.
+                $field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('user', 'user');
+                foreach ($field_definitions as $field_name => $field_definition) {
+                    if (isset($form[$field_name]) && $field_definition instanceof \Drupal\Core\Config\Entity\ThirdPartySettingsInterface) {
+                        $field_roles = array_filter($field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form', [
+                        ]));
+                        $field_roles_required = array_filter($field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form_required', [
+                        ]));
+                        if (!empty($field_roles)) {
+                            // If something was selected.
+                            if ($form[$field_name]['#access'] !== false) {
+                                $form[$field_name]['#access'] = \Drupal\multiple_registration\Controller\MultipleRegistrationController::checkFieldAccess($field_roles);
+                                $form[$field_name]['widget']['#required'] = \Drupal\multiple_registration\Controller\MultipleRegistrationController::checkFieldAccess($field_roles_required);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        $route_match = \Drupal::routeMatch();
+        $route = $route_match->getRouteObject();
+        $route_name = $route_match->getRouteName();
+        if ($route !== NULL && $route_name === 'multiple_registration.role_registration_page' && $form_id === 'user_register_form') {
+            $rid = \Drupal::routeMatch()->getParameter('rid');
+            // Hidden field to pass the rid.
+            $form['multiple_registration_rid'] = [
+                '#type' => 'hidden',
+                '#value' => $rid,
+            ];
+            // Custom submit handler to store the rid.
+            $form['actions']['submit']['#submit'][] = '_multiple_registration_rid';
+        }
+    }
+    /**
+     * Implements hook_field_widget_single_element_form_alter().
+     */
+    #[Hook('field_widget_single_element_form_alter')]
+    public static function fieldWidgetSingleElementFormAlter(array &$element, \Drupal\Core\Form\FormStateInterface $form_state, array $context)
+    {
+        $field_definition = $context['items']->getFieldDefinition();
+        $field_name = $field_definition->getName();
+        $parents = $context['form']['#parents'];
+        $widget_state = \Drupal\Core\Field\WidgetBase::getWidgetState($parents, $field_name, $form_state);
+        if ($field_definition->getTargetEntityTypeId() === 'user' && $field_definition instanceof \Drupal\Core\Config\Entity\ThirdPartySettingsInterface) {
+            if ($field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form')) {
+                $field_roles = $field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form');
+            } else {
+                $field_roles = [
+                ];
+            }
+            if ($field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form_required')) {
+                $field_roles_required = $field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form_required');
+            } else {
+                $field_roles_required = [
+                ];
+            }
+            // Conditions for AJAX triggers and paragraphs with removed states.
+            $has_not_triggering_elements = $form_state->getTriggeringElement() === NULL;
+            $paragraphs_with_removed_mode = !isset($form_state->getTriggeringElement()['#paragraphs_mode']) && (isset($form_state->getTriggeringElement()['#paragraphs_mode']) && $form_state->getTriggeringElement()['#paragraphs_mode'] !== 'removed');
+            // If something was selected.
+            if (!empty($field_roles) && max($field_roles) !== 0) {
+                if ($has_not_triggering_elements || $paragraphs_with_removed_mode) {
+                    $element['#access'] = \Drupal\multiple_registration\Controller\MultipleRegistrationController::checkFieldAccess($field_roles);
+                }
+            }
+            if ((!isset($element['#required']) || $element['#required'] === FALSE) && !empty($field_roles_required)) {
+                // If something was selected.
+                if (max($field_roles_required) !== 0) {
+                    $required = \Drupal\multiple_registration\Controller\MultipleRegistrationController::checkFieldAccess($field_roles_required);
+                    $element['#required'] = $required;
+                    // Fix 'N/A' element option for 'required' widgets to make them
+                    // similar with core widgets behaviour.
+                    if (isset($element['#options']['_none'])) {
+                        if ($element['#type'] === 'radios' || $element['#type'] === 'checkboxes') {
+                            unset($element['#options']['_none']);
+                        }
+                        if ($element['#type'] === 'select') {
+                            $element['#options']['_none'] = \Drupal::translation()->translate('- Select a value -');
+                        }
+                    }
+                    foreach (\Drupal\Core\Render\Element::children($element) as $child) {
+                        if ($widget_state['items_count'] === 0 || isset($element[$child]['#delta']) && $element[$child]['#delta'] < $widget_state['items_count']) {
+                            $element[$child]['#required'] = $required;
+                        }
+                    }
+                }
+            }
+        }
+    }
+    /**
+     * Implements hook_form_FORM_ID_alter().
+     */
+    #[Hook('form_user_register_form_alter')]
+    public static function formUserRegisterFormAlter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
+    {
+        $route_match = \Drupal::routeMatch();
+        $route = $route_match->getRouteName();
+        $current_user = \Drupal::currentUser();
+        if ($route === 'multiple_registration.role_registration_page') {
+            // Redirect authenticated user to user profile page instead of reg. form.
+            if ($current_user->isAuthenticated()) {
+                \Drupal::service('multiple_registration.controller_service')->authenticatedUserRedirect($current_user);
+            }
+            $rid = $route_match->getParameter('rid');
+            // Adding role id to the form array.
+            $form['rid'] = [
+                '#type' => 'value',
+                '#value' => $rid,
+            ];
+            $form['#validate'][] = 'multiple_registration_user_register_form_validate';
+        }
+    }
+    /**
+     * Implements hook_block_view_BASE_BLOCK_ID_alter().
+     */
+    #[Hook('block_view_user_login_block_alter')]
+    public function blockViewUserLoginBlockAlter(array &$build, \Drupal\Core\Block\BlockPluginInterface $block)
+    {
+        if (isset($build['content']['user_links'])) {
+            if (\Drupal::config('user.settings')->get('register') !== \Drupal\user\UserInterface::REGISTER_ADMINISTRATORS_ONLY) {
+                $reg_pages = \Drupal::service('multiple_registration.service')->getRegistrationPages();
+                foreach ($reg_pages as $rid => $role) {
+                    $uri = 'base:' . $role['url'];
+                    $reg_url = \Drupal\Core\Url::fromUri($uri);
+                    $reg_link = \Drupal\Core\Link::fromTextAndUrl($this->t('Create new @role account', [
+                        '@role' => $role['role_name'],
+                    ]), $reg_url);
+                    $build['content']['user_links']['#items']['multiple_registration_' . $rid] = $reg_link;
+                }
+            }
+        }
+    }
+    /**
+     * Implements hook_ENTITY_TYPE_insert().
+     */
+    #[Hook('user_insert')]
+    public static function userInsert(\Drupal\Core\Entity\EntityInterface $entity)
+    {
+        try {
+            multiple_registration_handle_user_entity($entity);
+        } catch (\Exception $exception) {
+            \Drupal::logger('multiple_registration')->notice($exception->getMessage());
+        }
+    }
+    /**
+     * Implements hook_ENTITY_TYPE_presave().
+     */
+    #[Hook('user_presave')]
+    public static function userPresave(\Drupal\Core\Entity\EntityInterface $entity)
+    {
+        try {
+            multiple_registration_handle_user_entity($entity);
+        } catch (\Exception $exception) {
+            \Drupal::logger('multiple_registration')->notice($exception->getMessage());
+        }
+    }
+    /**
+     * Implements hook_views_pre_view().
+     */
+    #[Hook('views_pre_view')]
+    public function viewsPreView(\Drupal\views\ViewExecutable $view, $display_id, array &$args)
+    {
+        $enable_buttons = \Drupal::config('multiple_registration.common_settings_page_form_config')->get('enable_add_user_buttons_on_people_page');
+        if (!$enable_buttons) {
+            return;
+        }
+        if ($view->id() == 'user_admin_people' && $display_id === 'page_1') {
+            $result = [
+            ];
+            $service = \Drupal::service('multiple_registration.service');
+            $available_roles = $service->getRegistrationPages();
+            foreach ($available_roles as $role) {
+                $link_label = $this->t('Add new @role', [
+                    '@role' => $role['role_name'],
+                ], [
+                    'context' => 'multiple_registration',
+                ]);
+                $result[] = '<a class="button button-action button--primary button--small" href="' . $role["url"] . '">' . $link_label . '</a>';
+            }
+            $options = [
+                'id' => 'add_new_user_buttons',
+                'table' => 'views',
+                'field' => 'area_text_custom',
+                'relationship' => 'none',
+                'group_type' => 'none',
+                'admin_label' => '',
+                'empty' => TRUE,
+                'tokenize' => FALSE,
+                'content' => implode($result),
+                'plugin_id' => 'text_custom',
+            ];
+            $view->setHandler('page_1', 'header', 'add_new_user_buttons', $options);
+        }
+    }
+}
