It's all in the title.

Issue fork domain-3573820

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mably created an issue. See original summary.

mably’s picture

Status: Active » Needs review
mably’s picture

Converted all Domain module procedural hooks to OOP format using #[Hook] attributes, with #[LegacyHook] delegates in .module files for Drupal 10.x backward compatibility.

Hook classes created/updated

domain module:

  • DomainHooks — hook_help, hook_domain_references_alter
  • DomainThemeHooks — hook_theme, preprocess_html, preprocessDomainNavBlock (via initial preprocess)
  • DomainEntityHooks — form_user_form_alter, views_data_alter
  • DomainTokenHooks — token_info, tokens

domain_access module:

  • DomainAccessEntityHooks — entity presave/insert/delete/predelete, entity_prepare_form, entity_field_access, entity_bundle_field_info_alter, node_type_insert, entity_form_display_insert
  • DomainAccessNodeHooks — node_grants, node_access_records, node_access, node_create_access
  • DomainAccessFormHooks — form_alter, form_node_form_alter, form_user_form_alter, form_devel_generate_form_content_alter, form_devel_generate_form_user_alter, form_field_config_edit_form_alter
  • DomainAccessViewsHooks — views_data_alter
  • DomainAccessDomainHooks — domain_references_alter, domain_insert, domain_delete

domain_source module:

  • DomainSourceEntityHooks — entity_update, node_presave, node_type_insert, entity_form_display_insert, domain_insert, domain_delete
  • DomainSourceFormHooks — form_alter, form_node_form_alter, form_devel_generate_form_content_alter
  • DomainSourceTokenHooks — token_info, tokens
  • DomainSourceViewsHooks — views_data_alter

domain_alias module:

  • DomainAliasHooks — domain_request_alter, domain_operations, domain_load, domain_delete

domain_config_ui module:

  • DomainConfigUiFormHooks — form_alter

domain_content module:

  • DomainContentHooks — domain_operations

Test modules:

  • domain_test — DomainTestHooks (5 hooks)
  • domain_config_hook_test — DomainConfigHookTestHooks (2 hooks)
  • domain_config_test — DomainConfigTestHooks (2 hooks)
  • domain_config_ui_hook_test — DomainConfigUiHookTestHooks (1 hook)
  • domain_source_test — DomainSourceTestHooks (1 hook)

Helper services created

  • DomainAccessHelper / DomainAccessHelperInterface — extracted domain_access_confirm_fields() logic
  • DomainSourceHelper / DomainSourceHelperInterface — extracted domain_source_confirm_fields(), domain_source_get(), domain_source_get_source_domain() logic

Deprecated procedural functions

All deprecated functions are thin wrappers delegating to their OOP equivalents:

  • domain_uri() -> Domain::uri()
  • template_preprocess_domain_nav_block() -> DomainThemeHooks::preprocessDomainNavBlock()
  • domain_access_confirm_fields() -> DomainAccessHelper::confirmFields()
  • domain_source_confirm_fields() -> DomainSourceHelper::confirmFields()
  • domain_source_get() -> DomainSourceHelper::getSourceDomainId()
  • domain_source_get_source_domain() -> DomainSourceHelper::getSourceDomain()
  • _domain_source_create_domain_source_set_action() -> DomainSourceEntityHooks::createDomainSourceSetAction()

Other improvements

  • Used Drupal 11.3's initial preprocess key in hook_theme() for the domain nav block preprocess callback
  • Moved uri_callback to a static method on the Domain entity class
  • Updated all test files to use $this->container->get() instead of \Drupal::service()

All 133 tests pass (3560 assertions).

mably’s picture

Bug fixes

  1. DomainSourceTestHooks.php — Removed stray var_dump($path) debug output.
  2. domain_source.module — Fixed wrong deprecation target: DomainSourceElementManagerInterfaceDomainSourceHelperInterface for domain_source_get_source_domain().
  3. DomainAccessEntityHooks + domain_access.module — Removed dead entityFormDisplayInsert() hook that checked $entity instanceof NodeInterface on an EntityFormDisplay entity (always false). Already covered by nodeTypeInsert().
  4. DomainSourceEntityHooks + domain_source.module — Same dead hook removal + cleaned unused NodeInterface import.

Style / cleanup

  1. DomainConfigUiFormHooks.php — Removed unnecessary ContainerInjectionInterface implementation and create() factory method (class is already registered as an autowired service).
  2. DomainAliasHooks.php — Converted static variables to instance properties ($aliasesCache, $patternCache). Removed dead url.site cache context check (always true since DomainServiceProvider adds it automatically). Removed $rendererConfig constructor param and %renderer.config% service argument.
  3. DomainAccessNodeHooks.php — Removed unnecessary static $active_domain caching (negotiator already caches internally).
  4. domain.module — Fixed deprecation notice: unqualified DomainHooks → fully qualified \Drupal\domain\Hook\DomainThemeHooks (also corrected the class name).

Documentation

  1. README.md — Updated "Domains and caching" section: url.site is now automatically added by DomainServiceProvider, no manual services.yml configuration needed. Added note for users upgrading from older versions.
  2. domain_alias/README.md — Same update: removed manual url.site configuration step, noted it is now handled automatically.
mably’s picture

Breaking change: The constructor of DomainSourcePathProcessor has a new required parameter DomainSourceHelperInterface $sourceHelper, inserted before the optional $languageNegotiator parameter. Any module that decorates or extends this service with an explicit constructor call will need to be updated. The new parameter is autowired, so standard service definitions using autowiring are not affected.

  • mably committed cf25f1b8 on 3.x
    task: #3573820 Convert all hooks to OOP format
    
    By: mably
    
mably’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • mably committed b92dfb3d on 3.x
    task: #3573820 Convert all hooks to OOP format (suite)
    
    By: mably
    
mably’s picture

Convert hook_requirements() to OOP #[Hook('runtime_requirements')] for both domain and domain_content sub-modules.

Changes

domain/domain.install

  • Added #[LegacyRequirementsHook] attribute on domain_requirements() to suppress the deprecation on Drupal 11.3+ and prevent double execution.
  • Replaced inline runtime logic with delegation to DomainHooks::runtimeRequirements(), guarded by a $phase === 'runtime' check to avoid calling the service before the module is installed.

domain/src/Hook/DomainHooks.php

  • Added EntityTypeManagerInterface dependency (autowired).
  • Added runtimeRequirements() method with #[Hook('runtime_requirements')] — contains the duplicate domain ID detection logic previously in the procedural hook, now using $this->entityTypeManager and $this->t() instead of static \Drupal calls.

domain_content/domain_content.install

  • Added #[LegacyRequirementsHook] attribute on domain_content_requirements() with the same phase-guarded delegation pattern.

domain_content/src/Hook/DomainContentHooks.php

  • Added ModuleHandlerInterface and ConfigFactoryInterface dependencies (autowired).
  • Added runtimeRequirements() method with #[Hook('runtime_requirements')] — contains the Domain Access field validation logic, now using injected services instead of static \Drupal calls.

Backward compatibility

  • On Drupal 10.x: #[LegacyRequirementsHook] is ignored, the procedural function runs normally and delegates to the OOP method.
  • On Drupal 11.3+: #[LegacyRequirementsHook] prevents the procedural function from running, the OOP #[Hook('runtime_requirements')] is called directly by the hook system.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.