metatag_google_plus.metatag.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * @file
  4. * Metatag integration for the Metatag Google+ module.
  5. */
  6. /**
  7. * Implements hook_metatag_bundled_config_alter().
  8. */
  9. function metatag_google_plus_metatag_bundled_config_alter(array &$configs) {
  10. foreach ($configs as &$config) {
  11. switch ($config->instance) {
  12. case 'global':
  13. $config->config += array(
  14. 'itemprop:name' => array('value' => '[current-page:title]'),
  15. );
  16. break;
  17. case 'global:frontpage':
  18. $config->config += array(
  19. 'itemprop:name' => array('value' => '[site:name]'),
  20. 'itemprop:description' => array('value' => '[site:slogan]'),
  21. );
  22. break;
  23. // On error pages point everything to the homepage.
  24. case 'global:403':
  25. case 'global:404':
  26. $config->config += array(
  27. 'itemprop:name' => array('value' => '[site:name]'),
  28. );
  29. break;
  30. case 'node':
  31. $config->config += array(
  32. 'itemprop:description' => array('value' => '[node:summary]'),
  33. 'itemprop:name' => array('value' => '[node:title]'),
  34. 'itemtype' => array('value' => 'Article'),
  35. );
  36. break;
  37. case 'taxonomy_term':
  38. $config->config += array(
  39. 'itemprop:description' => array('value' => '[term:description]'),
  40. 'itemprop:name' => array('value' => '[term:name]'),
  41. );
  42. break;
  43. case 'user':
  44. $config->config += array(
  45. 'itemprop:name' => array('value' => '[user:name]'),
  46. 'itemtype' => array('value' => 'Person'),
  47. );
  48. if (variable_get('user_pictures')) {
  49. $config->config += array(
  50. 'itemprop:image' => array('value' => '[user:picture:url]'),
  51. );
  52. }
  53. break;
  54. }
  55. }
  56. }
  57. /**
  58. * Implements hook_metatag_info().
  59. */
  60. function metatag_google_plus_metatag_info() {
  61. $info['groups']['google-plus'] = array(
  62. 'label' => t('Google+'),
  63. 'description' => t('A set of meta tags specially for controlling the summaries displayed when content is shared on <a href="!url">Google+</a>.', array('!url' => 'https://plus.google.com/')),
  64. 'form' => array(
  65. '#weight' => 80,
  66. ),
  67. );
  68. // Google+ meta tags stack after the Twitter Cards tags.
  69. $weight = 60;
  70. // Defaults used for all cards.
  71. $defaults = array(
  72. 'class' => 'DrupalTextMetaTag',
  73. 'group' => 'google-plus',
  74. 'element' => array(
  75. '#theme' => 'metatag_google_plus',
  76. ),
  77. );
  78. $info['tags']['itemtype'] = array(
  79. 'label' => t('Page type'),
  80. 'description' => t('Schema type. <a href="!url">More schema info</a>. If your page type does not exist in options above, please install <a href="!url2">select_or_other</a> module to enter page type manually.', array('!url' => 'http://schema.org/docs/schemas.html', '!url2' => 'https://drupal.org/project/select_or_other')),
  81. 'class' => 'DrupalSchemaMetaTag',
  82. 'weight' => ++$weight,
  83. 'select_or_other' => TRUE,
  84. 'form' => array(
  85. '#type' => 'select',
  86. '#options' => array(
  87. 'Article' => t('Article'),
  88. 'Blog' => t('Blog'),
  89. 'Book' => t('Book'),
  90. 'Event' => t('Event'),
  91. 'LocalBusiness' => t('Local Business'),
  92. 'Organization' => t('Organization'),
  93. 'Person' => t('Person'),
  94. 'Product' => t('Product'),
  95. 'Review' => t('Review'),
  96. ),
  97. '#empty_option' => t('- None -'),
  98. ),
  99. ) + $defaults;
  100. $info['tags']['itemprop:name'] = array(
  101. 'label' => t('Title'),
  102. 'description' => t('A Google+ title for the page being shared. Keep keywords towards the front.'),
  103. 'weight' => ++$weight,
  104. ) + $defaults;
  105. $info['tags']['itemprop:description'] = array(
  106. 'label' => t('Description'),
  107. 'description' => t('Longer form description, you’ve 200 words here that can specifically reference your presence on Google+'),
  108. 'weight' => ++$weight,
  109. ) + $defaults;
  110. $info['tags']['itemprop:image'] = array(
  111. 'label' => t('Image URL'),
  112. 'description' => t('The URL to a unique image representing the content of the page. Do not use a generic image such as your website logo, author photo, or other image that spans multiple pages. '),
  113. 'weight' => ++$weight,
  114. 'image' => TRUE,
  115. 'devel_generate' => array(
  116. 'type' => 'image',
  117. ),
  118. ) + $defaults;
  119. return $info;
  120. }