metatag_context.module 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_entity_prepare_view().
  80. */
  81. function metatag_context_entity_prepare_view($entities, $entity_type, $langcode = NULL) {
  82. // Store the current entities.
  83. drupal_static('metatag_context_entities', array($entity_type, $entities));
  84. }
  85. /**
  86. * Implements hook_page_alter().
  87. */
  88. function metatag_context_page_alter(&$page) {
  89. // By default do not add meta tags to admin pages. To enable meta tags on
  90. // admin pages set the 'metatag_tag_admin_pages' variable to TRUE.
  91. if (path_is_admin(current_path()) && !variable_get('metatag_tag_admin_pages', FALSE)) {
  92. return;
  93. }
  94. // Load the meta tags that have been generated for this page.
  95. $metatags = drupal_static('metatag_context', array());
  96. if (!empty($metatags)) {
  97. // The page region can be changed.
  98. $region = variable_get('metatag_page_region', 'content');
  99. $page[$region]['metatags']['context'] = $metatags;
  100. }
  101. }
  102. /**
  103. * Implements hook_ctools_plugin_api().
  104. */
  105. function metatag_context_ctools_plugin_api() {
  106. list($module, $api) = func_get_args();
  107. if ($module == "context" && $api == "context") {
  108. return array("version" => "3");
  109. }
  110. }
  111. /**
  112. * Implements hook_module_implements_alter().
  113. */
  114. function metatag_context_module_implements_alter(&$implementations, $hook) {
  115. if ($hook == 'page_alter') {
  116. // Run metatag_context_page_alter() last.
  117. $group = $implementations['metatag_context'];
  118. unset($implementations['metatag_context']);
  119. $implementations['metatag_context'] = $group;
  120. }
  121. }