domain_source.api.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @file
  4. * API documentation file for Domain Source module.
  5. */
  6. /**
  7. * Allows modules to specify the target domain for an entity.
  8. *
  9. * There is no return value for this hook. Modify $source by reference by
  10. * loading a valid domain record or set $source = NULL to discard an existing
  11. * $source value and not rewrite the path.
  12. *
  13. * Note that $options['entity'] is the entity for the path request and
  14. * $options['entity_type'] is the type of entity (e.g. 'node').
  15. * These values have already been verified before this hook is called.
  16. *
  17. * If the entity's path is a translation, the requested translation of the
  18. * entity will be passed as the $entity value.
  19. *
  20. * @param \Drupal\domain\Entity\Domain|NULL &$source
  21. * A domain object or NULL if not set.
  22. * @param string $path
  23. * The outbound path request.
  24. * @param array $options
  25. * The options for the url, as defined by
  26. * \Drupal\Core\PathProcessor\OutboundPathProcessorInterface.
  27. */
  28. function hook_domain_source_alter(&$source, $path, $options) {
  29. // Always link to the default domain.
  30. $source = \Drupal::service('entity_type.manager')->getStorage('domain')->loadDefaultDomain();
  31. }
  32. /**
  33. * Allows modules to specify the target link for a Drupal path.
  34. *
  35. * Note: This hook is not meant to be used for node or entity paths, which
  36. * are handled by hook_domain_source_alter(). This hook is split
  37. * from hook_domain_source_alter() for better performance.
  38. *
  39. * Note that hook_domain_source_alter() only paths that are not content entities.
  40. *
  41. * Currently, no modules in the package implement this hook.
  42. *
  43. * There is no return value for this hook. Modify $source by reference by
  44. * loading a valid domain record or set $source = NULL to discard an existing
  45. * $source value and not rewrite the path.
  46. *
  47. * @param array &$source
  48. * The domain array from domain_get_node_match(), passed by reference.
  49. * @param string $path
  50. * The outbound path request.
  51. * @param array $options
  52. * The options for the url, as defined by
  53. * \Drupal\Core\PathProcessor\OutboundPathProcessorInterface.
  54. */
  55. function hook_domain_source_path_alter(&$source, $path, $options) {
  56. // Always make admin links go to the primary domain.
  57. $parts = explode('/', $path);
  58. if (isset($parts[0]) && $parts[0] == 'admin') {
  59. $source = \Drupal::service('entity_type.manager')->getStorage('domain')->loadDefaultDomain();
  60. }
  61. }