drupal theme

Public

_preprocess_page

</> CopyGet raw version
php
  1. $item = menu_get_item();
  2. $paths = array(
  3. 'front',
  4. 'landing/recipe/%',
  5. 'landing/nutrition/%',
  6. 'landing/just_for_fun/%',
  7. 'landing/morning_tips/%',
  8. 'landing/olympics/%',
  9. );
  10. // Prepare the callouts for the landing pages.
  11. if (in_array($item['path'], $paths)) {
  12. // Get node type.
  13. $page = page_manager_get_current_page();
  14. $type = $page['arguments'][0];
  15. $display = panels_get_current_page_display();
  16.  
  17. // For the HP and USOC landing page we use different view/display to get the first
  18. // featured article.
  19. if ($item['path'] == 'front') {
  20. $result = views_get_view_result('home_page_featured_content', 'panel_pane_3');
  21. }
  22. elseif ($item['path'] == 'landing/olympics/%') {
  23. // Get the view result for the featured article.
  24. $result = views_get_view_result('usoc_featured_content', 'panel_pane_6');
  25. }
  26. else {
  27. // Get the view result for the featured article.
  28. $result = views_get_view_result('home_page_featured_content', 'panel_pane_2', $type);
  29. }
  30. $featured_article = reset($result);
  31. $featured_article_wrapper = entity_metadata_wrapper('node', $featured_article->nid);
  32.  
  33. // Build the callout array. If the article has values set use them. Otherwise just
  34. // fallback to the title and body/directions.
  35. if (!empty($featured_article_wrapper->field_callout_top->value()) || !empty($featured_article_wrapper->field_callout_bottom->value())) {
  36. $callout['title'] = !empty($featured_article_wrapper->field_callout_top->value()) ? $featured_article_wrapper->field_callout_top->value() : '';
  37. $callout['description'] = !empty($featured_article_wrapper->field_callout_bottom->value()) ? $featured_article_wrapper->field_callout_bottom->value() : '';
  38. }
  39. else {
  40. $callout['title'] = $display->title;
  41. $callout['description'] = $featured_article_wrapper->label();
  42. }
  43.  
  44. // If the title is disabled clear the callout text fields.
  45. if (!empty($featured_article_wrapper->field_disable_title_on_callout->value())) {
  46. $callout['title'] = '';
  47. $callout['description'] = '';
  48. }
  49.  
  50. $callout['link'] = $GLOBALS['base_url'] . '/' .drupal_get_path_alias('node/' . $featured_article->nid);
  51. $callout['link_text'] = 'Read more<svg viewBox="0 0 32 32" class="o-icon o-icon--angle-right"><use xlink:href="#icon--angle-right">';
  52. if (!empty($featured_article_wrapper->field_callout_big_image->value())) {
  53. $image = $featured_article_wrapper->field_callout_big_image->value();
  54. }
  55. else {
  56. $image = $featured_article_wrapper->field_main_image->value();
  57. }
  58. $callout['homepage_callout_image']['fid'] = $image['fid'];
  59.  
  60. // Handle an external callout.
  61. if (!empty($featured_article_wrapper->field_callout_external_link->value())) {
  62. $callout['is_external'] = TRUE;
  63. $external_link = $featured_article_wrapper->field_callout_external_link->value();
  64. $callout['link_text'] = $external_link['title'] ? $external_link['title'] . '<svg viewBox="0 0 32 32" class="o-icon o-icon--angle-right"><use xlink:href="#icon--angle-right">' : '';
  65. $callout['link'] = $external_link['url'];
  66. $callout['open_new_window'] = !$external_link['attributes']['target'] ? FALSE : TRUE;
  67.  
  68. // In case this is an external link and link title is empty, link the whole
  69. // image to the URL given.
  70. if (empty($callout['link_text'])) {
  71. $callout['whole_image_clickable'] = TRUE;
  72. }
  73. }
  74.  
  75. $callout['nid'] = $featured_article->nid;
  76. $callout['is_featured_video'] = FALSE;
  77. // If the Callout is actually a featured video, make the required changes to the callout.
  78. if (!empty($featured_article_wrapper->field_feature_as_video_content->value()) && !empty($featured_article_wrapper->field_feature_as_video_content->value())) {
  79. $callout['link_text'] = '<svg viewBox="0 0 32 32" class="o-icon o-icon--play o-icon--margin--right"><use xlink:href="#icon--play"></use></svg> Watch now';
  80. $callout['featured_video'] = $featured_article_wrapper->field_featured_video_url->value();
  81.  
  82. $matches = NULL;
  83. preg_match('/src="([^"]*)/', $callout['featured_video'], $matches);
  84. if ($matches) {
  85. $callout['featured_video'] = str_replace($matches[1], $matches[1] .'?&controls=1&rel=0&enablejsapi=1&color=white&playsinline=1', $callout['featured_video']);
  86. $callout['featured_video'] = str_replace('allowfullscreen>', 'frameborder="0" allowfullscreen>', $callout['featured_video']);
  87. }
  88.  
  89. $callout['is_featured_video'] = TRUE;
  90. }
  91. $vars['callout'] = theme('callout_marquee_image', array('callout' => $callout));
  92. }