entity_translation.api.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /**
  3. * @file
  4. * API documentation for the Entity translation module.
  5. */
  6. /**
  7. * Allows modules to define their own translation info.
  8. *
  9. * Entity Translation relies on the core entity information to provide its
  10. * translation features. See the documentation of hook_entity_info() in the core
  11. * API documentation (system.api.php) for more details on all the entity info
  12. * keys that may be defined.
  13. *
  14. * To make Entity Translation automatically support an entity type some keys
  15. * may need to be defined, but none of them is required except the 'base path'
  16. * key if the entity path is different from ENTITY_TYPE/%ENTITY_TYPE (e.g.
  17. * taxonomy/term/1). The 'base path' key is used to determine the view, edit and
  18. * translate path if they follow the default path patterns and to reliably
  19. * alter menu information to provide the translation UI. If the entity path
  20. * matches the default pattern above, and there is no need for a dedicated
  21. * translation handler class, Entity Translation will provide built-in support
  22. * for the entity.
  23. *
  24. * The entity translation info is an associative array that has to match the
  25. * following structure. Three nested sub-arrays keyed respectively by entity
  26. * type, the 'translation' key and the 'entity_translation' key: the second one
  27. * is the key defined by the core entity system while the third one registers
  28. * Entity translation as a field translation handler. Elements:
  29. * - class: The name of the translation handler class, which is used to handle
  30. * the translation process. Defaults to 'EntityTranslationDefaultHandler'.
  31. * - base path: The base menu router path to which attach the administration
  32. * user interface. Defaults to ENTITY_TYPE/%ENTITY_TYPE.
  33. * - access callback: The access callback for the translation pages. Defaults to
  34. * 'entity_translation_tab_access'.
  35. * - access arguments: The access arguments for the translation pages. Defaults
  36. * to "array($entity_type, $entity_position)".
  37. * - view path: The menu router path to be used to view the entity. Defaults to
  38. * the base path.
  39. * - edit path: The menu router path to be used to edit the entity. Defaults to
  40. * "$base_path/edit".
  41. * - translate path: The menu router path to be used for attaching the
  42. * translation UI. Defaults to "$base_path/translate".
  43. * - path wildcard: The menu router path wildcard identifying the entity.
  44. * Defaults to %ENTITY_TYPE.
  45. * - admin theme: Whether the translation UI should use the administration
  46. * theme. Defaults to TRUE.
  47. * - path schemes: An array of menu router path schemes used for attaching the
  48. * entity translation UI. This element can be used to declare additional path
  49. * schemes, if an entity type uses multiple schemes for managing entities
  50. * (e.g. different schemes for different bundles). Each path scheme can define
  51. * the following elements (descriptions see above): 'base path', 'view path',
  52. * 'edit path', 'translate path', 'path wildcard' and 'admin theme'. All path
  53. * elements that are defined directly on the entity translation info array are
  54. * automatically added as a 'default' path scheme.
  55. * - theme callback: The callback to be used to determine the translation
  56. * theme. Defaults to 'variable_get'.
  57. * - theme arguments: The arguments to be used to determine the translation
  58. * theme. Defaults to "array('admin_theme')".
  59. * - edit form: The key to be used to retrieve the entity object from the form
  60. * state array. An empty value prevents Entity translation from performing
  61. * alterations to the entity form. Defaults to ENTITY_TYPE.
  62. * - skip original values access: A flag specifying whether skipping access
  63. * control when editing original values for this entity. Defaults to FALSE.
  64. * - bundle callback: A callback to check whether the passed bundle has entity
  65. * translation enabled. Defaults to TRUE for all bundles.
  66. * - default settings: The defaults to be applied to settings when an explicit
  67. * choice is missing.
  68. */
  69. function hook_entity_info() {
  70. $info['custom_entity'] = array(
  71. 'translation' => array(
  72. 'entity_translation' => array(
  73. 'class' => 'EntityTranslationCustomEntityHandler',
  74. 'base path' => 'custom_entity/%custom_entity',
  75. 'access callback' => 'custom_entity_tab_access',
  76. 'access arguments' => array(1),
  77. 'edit form' => 'custom_entity_form_state_key',
  78. 'bundle callback' => 'custom_entity_translation_enabled_bundle',
  79. 'default settings' => array(
  80. 'default_language' => LANGUAGE_NONE,
  81. 'hide_language_selector' => FALSE,
  82. ),
  83. ),
  84. ),
  85. );
  86. // Entity type which has multiple (e.g. bundle-specific) paths.
  87. $info['custom_entity_2'] = array(
  88. 'translation' => array(
  89. 'entity_translation' => array(
  90. 'class' => 'EntityTranslationCustomEntityHandler',
  91. 'path schemes' => array(
  92. 'default' => array(
  93. 'base path' => 'custom_entity_2/%custom_entity',
  94. 'path wildcard' => '%custom_entity',
  95. ),
  96. 'fancy' => array(
  97. // Base path is not required.
  98. 'edit path' => 'fancy/%entity/edit',
  99. 'path wildcard' => '%entity',
  100. ),
  101. ),
  102. )
  103. )
  104. );
  105. return $info;
  106. }
  107. /**
  108. * Allows modules to act when a new translation is added.
  109. *
  110. * @param $entity_type
  111. * The entity type.
  112. * @param $entity
  113. * The entity.
  114. * @param $translation
  115. * The inserted translation array.
  116. * @param $values
  117. * The translated set of values, if any.
  118. */
  119. function hook_entity_translation_insert($entity_type, $entity, $translation, $values = array()) {
  120. }
  121. /**
  122. * Allows modules to act when a translation is updated.
  123. *
  124. * @param $entity_type
  125. * The entity type.
  126. * @param $entity
  127. * The entity.
  128. * @param $translation
  129. * The updated translation array.
  130. * @param $values
  131. * The translated set of values, if any.
  132. */
  133. function hook_entity_translation_update($entity_type, $entity, $translation, $values = array()) {
  134. }
  135. /**
  136. * Allows modules to act when a translation is deleted.
  137. *
  138. * @param $entity_type
  139. * The entity type.
  140. * @param $entity
  141. * The entity.
  142. * @param $langcode
  143. * The langcode of the translation which was deleted.
  144. */
  145. function hook_entity_translation_delete($entity_type, $entity, $langcode) {
  146. }
  147. /**
  148. * Allows modules to act when a revision translation is deleted.
  149. *
  150. * @param $entity_type
  151. * The entity type.
  152. * @param $entity
  153. * The entity.
  154. * @param $langcode
  155. * The langcode of the revision translation which was deleted.
  156. */
  157. function hook_entity_translation_delete_revision($entity_type, $entity, $langcode) {
  158. }