metatag.api.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php
  2. /**
  3. * @file
  4. * API documentation for the Metatag module.
  5. */
  6. /**
  7. * To enable Metatag support in custom entities, add 'metatags' => TRUE to the
  8. * entity definition in hook_entity_info(), e.g.:
  9. *
  10. * /**
  11. * * Implements hook_entity_info().
  12. * *
  13. * * Taken from the Examples module.
  14. * * /
  15. * function entity_example_entity_info() {
  16. * $info['entity_example_basic'] = array(
  17. * 'label' => t('Example Basic Entity'),
  18. * 'controller class' => 'EntityExampleBasicController',
  19. * 'base table' => 'entity_example_basic',
  20. * 'uri callback' => 'entity_example_basic_uri',
  21. * 'fieldable' => TRUE,
  22. * 'metatags' => TRUE,
  23. * 'entity keys' => array(
  24. * 'id' => 'basic_id' , // The 'id' (basic_id here) is the unique id.
  25. * 'bundle' => 'bundle_type' // Bundle will be determined by the 'bundle_type' field
  26. * ),
  27. * 'bundle keys' => array(
  28. * 'bundle' => 'bundle_type',
  29. * ),
  30. * 'static cache' => TRUE,
  31. * 'bundles' => array(
  32. * 'first_example_bundle' => array(
  33. * 'label' => 'First example bundle',
  34. * 'admin' => array(
  35. * 'path' => 'admin/structure/entity_example_basic/manage',
  36. * 'access arguments' => array('administer entity_example_basic entities'),
  37. * ),
  38. * ),
  39. * ),
  40. * 'view modes' => array(
  41. * 'tweaky' => array(
  42. * 'label' => t('Tweaky'),
  43. * 'custom settings' => FALSE,
  44. * ),
  45. * )
  46. * );
  47. *
  48. * return $info;
  49. * }
  50. *
  51. * The definition of each bundle may be handled separately, thus support may be
  52. * disabled for the entity as a whole but enabled for individual bundles. This
  53. * is handled via the 'metatags' value on the bundle definition, e.g.:
  54. *
  55. * 'bundles' => array(
  56. * 'first_example_bundle' => array(
  57. * 'label' => 'First example bundle',
  58. * 'metatags' => TRUE,
  59. * 'admin' => array(
  60. * 'path' => 'admin/structure/entity_example_basic/manage',
  61. * 'access arguments' => array('administer entity_example_basic entities'),
  62. * ),
  63. * ),
  64. * ),
  65. */
  66. /**
  67. * Provides a default configuration for Metatag intances.
  68. *
  69. * This hook allows modules to provide their own Metatag instances which can
  70. * either be used as-is or as a "starter" for users to build from.
  71. *
  72. * This hook should be placed in MODULENAME.metatag.inc and it will be auto-
  73. * loaded. MODULENAME.metatag.inc *must* be in the same directory as the
  74. * .module file which *must* also contain an implementation of
  75. * hook_ctools_plugin_api, preferably with the same code as found in
  76. * metatag_ctools_plugin_api().
  77. *
  78. * The $config->disabled boolean attribute indicates whether the Metatag
  79. * instance should be enabled (FALSE) or disabled (TRUE) by default.
  80. *
  81. * @return
  82. * An associative array containing the structures of Metatag instances, as
  83. * generated from the Export tab, keyed by the Metatag config name.
  84. *
  85. * @see metatag_metatag_config_default()
  86. * @see metatag_ctools_plugin_api()
  87. */
  88. function hook_metatag_config_default() {
  89. $configs = array();
  90. $config = new stdClass();
  91. $config->instance = 'config1';
  92. $config->api_version = 1;
  93. $config->disabled = FALSE;
  94. $config->config = array(
  95. 'title' => array('value' => '[current-page:title] | [site:name]'),
  96. 'generator' => array('value' => 'Drupal 7 (http://drupal.org)'),
  97. 'canonical' => array('value' => '[current-page:url:absolute]'),
  98. 'shortlink' => array('value' => '[current-page:url:unaliased]'),
  99. );
  100. $configs[$config->instance] = $config;
  101. $config = new stdClass();
  102. $config->instance = 'config2';
  103. $config->api_version = 1;
  104. $config->disabled = FALSE;
  105. $config->config = array(
  106. 'title' => array('value' => '[user:name] | [site:name]'),
  107. );
  108. $configs[$config->instance] = $config;
  109. return $configs;
  110. }
  111. /**
  112. *
  113. */
  114. function hook_metatag_config_default_alter(&$config) {
  115. }
  116. /**
  117. *
  118. */
  119. function hook_metatag_config_delete($entity_type, $entity_ids, $revision_ids, $langcode) {
  120. }
  121. /**
  122. *
  123. */
  124. function hook_metatag_config_insert($config) {
  125. }
  126. /**
  127. *
  128. */
  129. function hook_metatag_config_instance_info() {
  130. return array();
  131. }
  132. /**
  133. *
  134. */
  135. function hook_metatag_config_instance_info_alter(&$info) {
  136. }
  137. /**
  138. *
  139. */
  140. function hook_metatag_config_load() {
  141. }
  142. /**
  143. *
  144. */
  145. function hook_metatag_config_load_presave() {
  146. }
  147. /**
  148. *
  149. */
  150. function hook_metatag_config_presave($config) {
  151. }
  152. /**
  153. *
  154. */
  155. function hook_metatag_config_update($config) {
  156. }
  157. /**
  158. *
  159. */
  160. function hook_metatag_info() {
  161. return array();
  162. }
  163. /**
  164. *
  165. */
  166. function hook_metatag_info_alter(&$info) {
  167. }
  168. /**
  169. *
  170. */
  171. function hook_metatag_load_entity_from_path_alter(&$path, $result) {
  172. }
  173. /**
  174. * Alter metatags before being cached.
  175. *
  176. * This hook is invoked prior to the meta tags for a given page are cached.
  177. *
  178. * @param array $output
  179. * All of the meta tags to be output for this page in their raw format. This
  180. * is a heavily nested array.
  181. * @param string $instance
  182. * An identifier for the current page's page type, typically a combination
  183. * of the entity name and bundle name, e.g. "node:story".
  184. */
  185. function hook_metatag_metatags_view_alter(&$output, $instance) {
  186. if (isset($output['description']['#attached']['drupal_add_html_head'][0][0]['#value'])) {
  187. $output['description']['#attached']['drupal_add_html_head'][0][0]['#value'] = 'O rly?';
  188. }
  189. }
  190. /**
  191. *
  192. */
  193. function hook_metatag_page_cache_cid_parts_alter(&$cid_parts) {
  194. }
  195. /**
  196. *
  197. */
  198. function hook_metatag_presave(&$metatags, $entity_type, $entity_id, $revision_id, $langcode) {
  199. }
  200. /**
  201. * Allows modules to alter the defined list of tokens available
  202. * for metatag patterns replacements.
  203. *
  204. * By default only context (for example: global, node, etc...)
  205. * related tokens are made available to metatag patterns replacements.
  206. * This hook allows other modules to extend the default declared tokens.
  207. *
  208. * @param array $options
  209. * (optional) An array of options including the following keys and values:
  210. * - token types: An array of token types to be passed to theme_token_tree().
  211. * - context: An identifier for the configuration instance type, typically
  212. * an entity name or object name, e.g. node, views, taxonomy_term.
  213. *
  214. * @see metatag_config_edit_form()
  215. * @see metatag_field_attach_form()
  216. */
  217. function hook_metatag_token_types_alter(&$options) {
  218. // Watchout: $options['token types'] might be empty
  219. if (!isset($options['token types'])) {
  220. $options['token types'] = array();
  221. }
  222. if ($options['context'] == 'config1'){
  223. $options['token types'] += array('token_type1','token_type2');
  224. }
  225. elseif ($options['context'] == 'config2'){
  226. $options['token types'] += array('token_type3','token_type4');
  227. }
  228. }
  229. /**
  230. * Allows modules to alter defined token patterns and values before replacement.
  231. *
  232. * The metatag module defines default token patterns replacements depending on
  233. * the different configuration instances (contexts, such as global, node, ...).
  234. * This hook provides an opportunity for other modules to alter the patterns or
  235. * the values for replacements, before tokens are replaced (token_replace).
  236. *
  237. * See facetapi and facetapi_bonus modules for an example of implementation.
  238. *
  239. * @param $pattern
  240. * A string potentially containing replaceable tokens. The pattern could also
  241. * be altered by reference, allowing modules to implement further logic, such
  242. * as tokens lists or masks/filters.
  243. * @param $types
  244. * Corresponds to the 'token data' property of the $options object.
  245. * (optional) An array of keyed objects. For simple replacement scenarios
  246. * 'node', 'user', and others are common keys, with an accompanying node or
  247. * user object being the value. Some token types, like 'site', do not require
  248. * any explicit information from $data and can be replaced even if it is
  249. * empty.
  250. *
  251. * @see DrupalTextMetaTag::getValue()
  252. */
  253. function hook_metatag_pattern_alter(&$pattern, &$types) {
  254. if (strpos($pattern, 'token_type1') !== FALSE) {
  255. $types['token_type1'] = "data to be used in hook_tokens for replacement";
  256. }
  257. if (strpos($pattern, 'token_type2') !== FALSE) {
  258. // Load something or do some operations.
  259. $types['token_type2'] = array("Then fill in the array with the right data");
  260. // $pattern could also be altered, for example, strip off [token_type3].
  261. $pattern = str_replace('[token_type3]', '', $pattern);
  262. }
  263. }