AliasStorageInterface.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace Drupal\Core\Path;
  3. use Drupal\Core\Language\LanguageInterface;
  4. /**
  5. * Provides a class for CRUD operations on path aliases.
  6. */
  7. interface AliasStorageInterface {
  8. /**
  9. * Saves a path alias to the database.
  10. *
  11. * @param string $source
  12. * The internal system path.
  13. * @param string $alias
  14. * The URL alias.
  15. * @param string $langcode
  16. * (optional) The language code of the alias.
  17. * @param int|null $pid
  18. * (optional) Unique path alias identifier.
  19. *
  20. * @return array|false
  21. * FALSE if the path could not be saved or an associative array containing
  22. * the following keys:
  23. * - source (string): The internal system path with a starting slash.
  24. * - alias (string): The URL alias with a starting slash.
  25. * - pid (int): Unique path alias identifier.
  26. * - langcode (string): The language code of the alias.
  27. * - original: For updates, an array with source, alias and langcode with
  28. * the previous values.
  29. *
  30. * @thrown \InvalidArgumentException
  31. * Thrown when either the source or alias has not a starting slash.
  32. */
  33. public function save($source, $alias, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, $pid = NULL);
  34. /**
  35. * Fetches a specific URL alias from the database.
  36. *
  37. * The default implementation performs case-insensitive matching on the
  38. * 'source' and 'alias' strings.
  39. *
  40. * @param array $conditions
  41. * An array of query conditions.
  42. *
  43. * @return array|false
  44. * FALSE if no alias was found or an associative array containing the
  45. * following keys:
  46. * - source (string): The internal system path with a starting slash.
  47. * - alias (string): The URL alias with a starting slash.
  48. * - pid (int): Unique path alias identifier.
  49. * - langcode (string): The language code of the alias.
  50. */
  51. public function load($conditions);
  52. /**
  53. * Deletes a URL alias.
  54. *
  55. * The default implementation performs case-insensitive matching on the
  56. * 'source' and 'alias' strings.
  57. *
  58. * @param array $conditions
  59. * An array of criteria.
  60. */
  61. public function delete($conditions);
  62. /**
  63. * Pre-loads path alias information for a given list of source paths.
  64. *
  65. * @param array $preloaded
  66. * Paths that need preloading of aliases.
  67. * @param string $langcode
  68. * Language code to search the path with. If there's no path defined for
  69. * that language it will search paths without language.
  70. *
  71. * @return string[]
  72. * Source (keys) to alias (values) mapping.
  73. */
  74. public function preloadPathAlias($preloaded, $langcode);
  75. /**
  76. * Returns an alias of Drupal system URL.
  77. *
  78. * The default implementation performs case-insensitive matching on the
  79. * 'source' and 'alias' strings.
  80. *
  81. * @param string $path
  82. * The path to investigate for corresponding path aliases.
  83. * @param string $langcode
  84. * Language code to search the path with. If there's no path defined for
  85. * that language it will search paths without language.
  86. *
  87. * @return string|false
  88. * A path alias, or FALSE if no path was found.
  89. */
  90. public function lookupPathAlias($path, $langcode);
  91. /**
  92. * Returns Drupal system URL of an alias.
  93. *
  94. * The default implementation performs case-insensitive matching on the
  95. * 'source' and 'alias' strings.
  96. *
  97. * @param string $path
  98. * The path to investigate for corresponding system URLs.
  99. * @param string $langcode
  100. * Language code to search the path with. If there's no path defined for
  101. * that language it will search paths without language.
  102. *
  103. * @return string|false
  104. * A Drupal system path, or FALSE if no path was found.
  105. */
  106. public function lookupPathSource($path, $langcode);
  107. /**
  108. * Checks if alias already exists.
  109. *
  110. * The default implementation performs case-insensitive matching on the
  111. * 'source' and 'alias' strings.
  112. *
  113. * @param string $alias
  114. * Alias to check against.
  115. * @param string $langcode
  116. * Language of the alias.
  117. * @param string|null $source
  118. * (optional) Path that alias is to be assigned to.
  119. *
  120. * @return bool
  121. * TRUE if alias already exists and FALSE otherwise.
  122. */
  123. public function aliasExists($alias, $langcode, $source = NULL);
  124. /**
  125. * Checks if there are any aliases with language defined.
  126. *
  127. * @return bool
  128. * TRUE if aliases with language exist.
  129. */
  130. public function languageAliasExists();
  131. /**
  132. * Loads aliases for admin listing.
  133. *
  134. * @param array $header
  135. * Table header.
  136. * @param string|null $keys
  137. * (optional) Search keyword that may include one or more '*' as wildcard
  138. * values.
  139. *
  140. * @return array
  141. * Array of items to be displayed on the current page.
  142. */
  143. public function getAliasesForAdminListing($header, $keys = NULL);
  144. /**
  145. * Check if any alias exists starting with $initial_substring.
  146. *
  147. * @param string $initial_substring
  148. * Initial path substring to test against.
  149. *
  150. * @return bool
  151. * TRUE if any alias exists, FALSE otherwise.
  152. */
  153. public function pathHasMatchingAlias($initial_substring);
  154. }