metatag_context.module 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * @file
  4. * Primary hook implementations for Metatag Context.
  5. */
  6. /**
  7. * Implements hook_menu().
  8. */
  9. function metatag_context_menu() {
  10. $items['admin/config/search/metatags/context'] = array(
  11. 'title' => 'By path',
  12. 'page callback' => 'metatag_context_context_overview',
  13. 'access arguments' => array('administer meta tags'),
  14. 'file' => 'metatag_context.admin.inc',
  15. 'type' => MENU_LOCAL_TASK,
  16. );
  17. $items['admin/config/search/metatags/context/add'] = array(
  18. 'title' => 'Add a meta tag by path',
  19. 'page callback' => 'drupal_get_form',
  20. 'page arguments' => array('metatag_context_config_add_form'),
  21. 'access arguments' => array('administer meta tags'),
  22. 'file' => 'metatag_context.admin.inc',
  23. 'type' => MENU_LOCAL_ACTION,
  24. );
  25. $items['admin/config/search/metatags/context/%context'] = array(
  26. 'title' => 'Configure metatags by path',
  27. 'page callback' => 'drupal_get_form',
  28. 'page arguments' => array('metatag_context_config_edit_form', 5),
  29. 'access arguments' => array('administer meta tags'),
  30. 'file' => 'metatag_context.admin.inc',
  31. );
  32. $items['admin/config/search/metatags/context/%context/delete'] = array(
  33. 'title' => 'Delete metatags by path',
  34. 'page callback' => 'drupal_get_form',
  35. 'page arguments' => array('metatag_context_delete_form', 5),
  36. 'access arguments' => array('administer meta tags'),
  37. 'file' => 'metatag_context.admin.inc',
  38. );
  39. return $items;
  40. }
  41. /**
  42. * Implements hook_context_plugins().
  43. */
  44. function metatag_context_context_plugins() {
  45. return array(
  46. 'metatag_context_reaction' => array(
  47. 'handler' => array(
  48. 'path' => drupal_get_path('module', 'metatag_context'),
  49. 'file' => 'metatag_context.context.inc',
  50. 'class' => 'metatag_context_reaction',
  51. 'parent' => 'context_reaction',
  52. ),
  53. ),
  54. );
  55. }
  56. /**
  57. * Implements hook_context_registry().
  58. */
  59. function metatag_context_context_registry() {
  60. return array(
  61. 'reactions' => array(
  62. 'metatag_context_reaction' => array(
  63. 'title' => t('Meta Data'),
  64. 'description' => t('Control page meta tags using the Metatag module.'),
  65. 'plugin' => 'metatag_context_reaction',
  66. ),
  67. ),
  68. );
  69. }
  70. /**
  71. * Implements hook_context_page_reaction().
  72. */
  73. function metatag_context_context_page_reaction() {
  74. if ($plugin = context_get_plugin('reaction', 'metatag_context_reaction')) {
  75. $plugin->execute();
  76. }
  77. }
  78. /**
  79. * Implements hook_page_build().
  80. */
  81. function metatag_context_page_build(&$page) {
  82. // Load the meta tags that have been generated for this page.
  83. $metatags = drupal_static('metatag_context', array());
  84. if (!empty($metatags)) {
  85. // The page region can be changed.
  86. $region = variable_get('metatag_page_region', 'content');
  87. $page[$region]['metatags']['global'] = $metatags;
  88. }
  89. }
  90. /**
  91. * Implements hook_preprocess_html().
  92. */
  93. function metatag_context_preprocess_html(&$variables) {
  94. $metadata = drupal_static('metatag_context');
  95. if (isset($metadata['metadata_title'])) {
  96. $variables['head_title'] = token_replace($metadata['metadata_title']);
  97. }
  98. }
  99. /**
  100. * Implements hook_ctools_plugin_api().
  101. */
  102. function metatag_context_ctools_plugin_api() {
  103. list($module, $api) = func_get_args();
  104. if ($module == "context" && $api == "context") {
  105. return array("version" => "3");
  106. }
  107. }