metatag_google_plus.metatag.inc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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' => '[current-page:title]'),
  20. );
  21. break;
  22. // On error pages point everything to the homepage.
  23. case 'global:403':
  24. case 'global:404':
  25. $config->config += array(
  26. 'itemprop:name' => array('value' => '[current-page:title]'),
  27. );
  28. break;
  29. case 'node':
  30. $config->config += array(
  31. 'itemprop:description' => array('value' => '[node:summary]'),
  32. 'itemprop:name' => array('value' => '[current-page:title]'),
  33. );
  34. break;
  35. case 'taxonomy_term':
  36. $config->config += array(
  37. 'itemprop:description' => array('value' => '[term:description]'),
  38. 'itemprop:name' => array('value' => '[term:name]'),
  39. );
  40. break;
  41. case 'user':
  42. $config->config += array(
  43. 'itemprop:name' => array('value' => '[user:name]'),
  44. );
  45. if (variable_get('user_pictures')) {
  46. $config->config += array(
  47. 'itemprop:image' => array('value' => '[user:picture:url]'),
  48. );
  49. }
  50. break;
  51. }
  52. }
  53. }
  54. /**
  55. * Implements hook_metatag_info().
  56. */
  57. function metatag_google_plus_metatag_info() {
  58. $info['groups']['google-plus'] = array(
  59. 'label' => t('Google+'),
  60. '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/')),
  61. 'form' => array(
  62. '#weight' => 70,
  63. ),
  64. );
  65. // Google+ meta tags stack after the Twitter Cards tags.
  66. $weight = 60;
  67. // Defaults used for all cards.
  68. $defaults = array(
  69. 'class' => 'DrupalTextMetaTag',
  70. 'group' => 'google-plus',
  71. 'element' => array(
  72. '#theme' => 'metatag_google_plus',
  73. ),
  74. );
  75. $info['tags']['itemtype'] = array(
  76. 'label' => t('Page type'),
  77. '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')),
  78. 'class' => 'DrupalSchemaMetaTag',
  79. 'weight' => ++$weight,
  80. 'form' => array(
  81. '#type' => 'select',
  82. '#options' => array(
  83. 'Article' => t('Article'),
  84. 'Blog' => t('Blog'),
  85. 'Book' => t('Book'),
  86. 'Event' => t('Event'),
  87. 'LocalBusiness' => t('Local Business'),
  88. 'Organization' => t('Organization'),
  89. 'Person' => t('Person'),
  90. 'Product' => t('Product'),
  91. 'Review' => t('Review'),
  92. ),
  93. '#empty_option' => t('- None -'),
  94. ),
  95. ) + $defaults;
  96. if (module_exists('select_or_other')) {
  97. $info['tags']['itemtype']['form']['#type'] = 'select_or_other';
  98. $info['tags']['itemtype']['form']['#other'] = 'Other (please type a value)';
  99. $info['tags']['itemtype']['form']['#multiple'] = FALSE;
  100. $info['tags']['itemtype']['form']['#other_unknown_defaults'] = 'other';
  101. $info['tags']['itemtype']['form']['#select_type'] = 'select';
  102. }
  103. $info['tags']['itemprop:name'] = array(
  104. 'label' => t('Title'),
  105. 'description' => t('A Google+ title for the page being shared. Keep keywords towards the front.'),
  106. 'weight' => ++$weight,
  107. ) + $defaults;
  108. $info['tags']['itemprop:description'] = array(
  109. 'label' => t('Description'),
  110. 'description' => t('Longer form description, you’ve 200 words here that can specifically reference your presence on Google+'),
  111. 'weight' => ++$weight,
  112. ) + $defaults;
  113. $info['tags']['itemprop:image'] = array(
  114. 'label' => t('Image URL'),
  115. '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. '),
  116. 'weight' => ++$weight,
  117. 'devel_generate' => array(
  118. 'type' => 'image',
  119. ),
  120. ) + $defaults;
  121. return $info;
  122. }