$child) { if($element[$key]['#description'] == 'Provide banner images for virtual site homepages on Scholar at Waterloo sites.') { $element[$key]['#process'][] = 'uw_virtual_site_homepage_image_field_widget_process'; } } } } /** * Implements hook_image_field_widget_process(). * Processing images to change title to caption for homepage banners. */ function uw_virtual_site_homepage_image_field_widget_process($element, &$form_state, $form) { // Set the title to be the caption and the description. //$element['title']['#title'] = 'Caption'; $element['title']['#description'] = 'The title is display with the picture.'; // Return the altered element return $element; } /** * Implements hook_page_alter(). * Placing homepage banners on the virtual site homepage. */ function uw_virtual_site_homepage_page_alter(&$page) { global $base_path; // Setting the variables to be used in homepage banners. $index = 0; $continue = true; if(isset($page['uw-virtual-site-homepage']['field_uw_faculty_list_logo'][0]['#markup'])) { $site_links = _uw_virtual_site_homepage_get_site_links(); if (isset($site_links[$page['uw-virtual-site-homepage']['field_uw_faculty_list_logo'][0]['#markup']])) { $site_link = $site_links[$page['uw-virtual-site-homepage']['field_uw_faculty_list_logo'][0]['#markup']]; $page['uw-virtual-site-homepage']['uw_scholar_row']['site_link'] = $site_link; } } // If there are banners, process them. if(isset($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index])) { // html divs in homepage banners. $html = '
'; $html .= '
'; $pagenumber = 0; $boxes = ''; $num_of_images = 0; // Get the number of images in the homepage banners. foreach($page['uw-virtual-site-homepage']['field_uw_homepage_banners'] as $key => $value) { if(is_int($key)) { $num_of_images++; } } // While there is a continue, process the homepage banners. while($continue) { foreach($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'] as $key => $value) { $fc_id = $key; break; } // Set theme paths, alt text and all banner sizes. $file = $page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_image'][0]['#item']['uri']; $theme_path = $base_path . drupal_get_path('theme', 'uw_virtual_site_homepage'); $banner_alt = 'Test ALT'; $banner_small = image_style_url('uw_homepage_banners', $file); $banner_square = image_style_url('uw_homepage_banners_small', $file); $banner_med = image_style_url('uw_homepage_banners_medium', $file); $banner_large = image_style_url('uw_homepage_banners_large', $file); $banner_xl = image_style_url('uw_homepage_banners_xl', $file); $pagenumber++; // Set the image. if($pagenumber == 1) { $html .= '
'; } else { $html .= '
'; } if(isset($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_link']['#items'][0]['url'])) { $html .= ''; } // Set the picture using the picture tag. $html .= ' '; $html .= '' . $banner_alt . ''; $html .= ''; // If there is a title, double check, and then set the caption. if(isset($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_image'][0]['#item']['title'])) { // If there is a title, set the caption. // If there is not title, check that there is a title for the link and use that. if($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_image'][0]['#item']['title'] !== "") { $html .= ''; } elseif (isset($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_link']['#items'][0]['title'])) { $html .= ''; } } if(isset($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_link']['#items'][0]['url'])) { $html .= ''; } // Increment the index. $index++; // If there are not any more homepage banners, stop processing the homepage banners. if(!(isset($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]))) { $continue = false; } // If there is more than one image add the paginator blocks. if($num_of_images > 1) { // More html. $html .= ''; $html .= '
'; if($pagenumber == 1) { $boxes .= '
  • Display banner #' . $pagenumber . '
  • '; } else { $boxes .= '
  • Display banner #' . $pagenumber . '
  • '; } } else{ $html .= '
    '; } } // If there is more than one image, add the Play/Pause button. if($num_of_images > 1) { // Final closing html and play/pause button. $html .= '
    '; $html .= ''; $html .= ''; $html .= '
    '; } else{ // close the opening html divs in homepage banners. if single image in banner $html .= ''; $html .= ''; } // Set the html to the page variable. $page['uw_virtual_page_homepage_banners_html'] = $html; } // If there is credentials in the virutal site homepage settings, add it to the header. if(isset($page['uw-virtual-site-homepage']['field_uw_credentials'])) { if(isset($page['header_second']['boxes_site_info']['content']['#markup'])) { $page['header_second']['boxes_site_info']['content']['#markup'] = preg_replace('/

    (.*)/s', '

    ' . $page['uw-virtual-site-homepage']['field_uw_credentials'][0]['#markup'] . '

    ', $page['header_second']['boxes_site_info']['content']['#markup']); } else if($page['header_second']['boxes_site_info']['#markup']) { $page['header_second']['boxes_site_info']['#markup'] = preg_replace('/

    (.*)/s', '

    ' . $page['uw-virtual-site-homepage']['field_uw_credentials'][0]['#markup'] . '

    ', $page['header_second']['boxes_site_info']['#markup']); } } } /** * Implement hook_form_alter * Form ID: _os_link_external_form * Hide target option field. */ function uw_virtual_site_homepage_form_alter(&$form, &$form_state, $form_id) { if($form_id == "biblio_search_form") { $form['search_form']['#collapsed'] = FALSE; $form['search_form']['#collapsible'] = FALSE; if(isset($form['search_form']['filterform']['filters']['current'][0]['#markup'])) { if($form['search_form']['filterform']['filters']['current'][0]['#markup'] !== "") { $form['search_form']['filterform']['filters']['#collapsed'] = FALSE; } } } if ($form_id == '_os_link_external_form' && isset($form['target_option'])) { unset($form['target_option']); } } /** * Implements hook_FORMID_form_alter(). * Removing options and placing data on the form for setting the virtual homepage. */ function uw_virtual_site_homepage_form_uw_virtual_site_homepage_node_form_alter(&$form, &$form_state, $form_id) { global $base_path; // Get current link. $url = request_uri(); // Ensure that we don't replace all the slashes if just at top root. if($base_path !== '/') { // Ensure that we are at the very base. $url = str_replace($base_path, '', $url); } // Break Url into its parts $url_parts = explode('/', $url); // The username should be the first element in the url_parts array, set it to username. // If the first element is blank use the second element. if($url_parts[0] == '') { $username = $url_parts[1]; } else { $username = $url_parts[0]; } // Set title to watiam id and disable title. $form['title']['#value'] = $username; $form['title']['#disabled'] = TRUE; $form['title']['#access'] = FALSE; // Removing elements from the page that we do not want set. $form['author']['#access'] = FALSE; $form['menu']['#access'] = FALSE; $form['path']['#access'] = FALSE; $form['options']['#access'] = FALSE; $form['og_group_ref']['#access'] = FALSE; $form['og_vocabulary']['#access'] = FALSE; $form['book']['#access'] = FALSE; $form['comment_settings']['#access'] = FALSE; // Getting the current space and loading that node. // This is the users vsite node. $space = spaces_get_space(); $node = $space->group; // Adding the site information group to the form. $form['site_info'] = array( '#type' => 'fieldset', '#title' => t('Site Information'), '#weight' => -999, ); // Adding the site title to the form. This is at the top of every page. $form['site_info']['site_title'] = array( '#type' => 'textfield', '#title' => t('Name'), '#default_value' => $node->title, '#description' => t('Enter your name as the title of your site. This will appear at the top of every page (for example: Dr John Doe).'), '#size' => 60, '#required' => true, ); // Ensuring that we are getting a default value. if(isset($node->field_site_description[LANGUAGE_NONE][0]['value'])) { $default_value = $node->field_site_description[LANGUAGE_NONE][0]['value']; } else { $default_value = ''; } // Move help text of site description from the bottom to the top of field_uw_site_description. if (isset($form['field_uw_site_description'][LANGUAGE_NONE][0]['#description'])) { $form['field_uw_site_description'][LANGUAGE_NONE][0]['#field_prefix'] = $form['field_uw_site_description'][LANGUAGE_NONE][0]['#description']; $form['field_uw_site_description'][LANGUAGE_NONE][0]['#description'] = ''; } // Adding the site description to the page. This is just below the site title and on every page. $form['site_info']['descrip'] = array( '#type' => 'textfield', '#title' => t('Title'), '#default_value' => $default_value, '#description' => t('Enter your academic role, position or title. This will appear under the site title at the top of every page (for example: Professor of Economics).'), '#size' => 60, ); $form['site_info']['field_uw_credentials'] = $form['field_uw_credentials']; unset($form['field_uw_credentials']); // Adding the site information submit callback. $form['actions']['submit']['#submit'][] = 'uw_vitual_site_homepage_site_information_form_submit'; // Adding the redirect back to the homepage after the save of the uw_virtual_site_homepage. $form['actions']['submit']['#submit'][] = 'uw_virtual_site_homepage_node_form_redirect'; // Adding the validate for removing duplicate buttons. $form['#validate'][] = 'uw_virtual_site_homepage_button_validate'; } /** * The validate buttons by adding css in order to remove duplicate buttons. */ function uw_virtual_site_homepage_button_validate(&$form, &$form_state) { } /** * Submit callback. * Saves site title and site description. */ function uw_vitual_site_homepage_site_information_form_submit($form, &$form_state) { if (module_exists('vsite') && $space = spaces_get_space()) { // Getting the current space and loading that node. // This is the users vsite node. $node = $space->group; // Setting the title from the form. This can not be blank and is validate because it is a required element on the form. $node->title = $form_state['values']['site_title']; // Setting the site description from the form. $node->field_site_description[LANGUAGE_NONE][0] = array( 'value' => $form_state['values']['descrip'], 'format' => NULL, ); if(isset($form_state['value']['field_uw_credentials'])) { $node->field_uw_credentials[LANGUAGE_NONE][0] = array( 'value' => $form_state['value']['field_uw_credentials'], 'format' => NULL, ); } // Ensuring that we get a save of the node which is the users vsite. try { node_save($node); } catch (Exception $e) { drupal_set_message(t('Error saving site information. Contact your site administrator.'), 'error'); error_log($e); } } } /** * Submit callback. */ function uw_virtual_site_homepage_node_form_redirect($form, &$form_state) { // Clear the caches of the landing page info, in case the site title has changed. cache_clear_all('ctools_export:views_view:uw_os_number_of_sites', 'cache_views', TRUE); cache_clear_all('uw_os_number_of_sites', 'cache_views_data', TRUE); // Unset destination first. unset($_GET['destination']); unset($_REQUEST['edit']['destination']); // Redirecting to home page after a save. $form_state['redirect'] = 'home'; } function _uw_virtual_site_homepage_get_site_links() { // Array that stores all of links. $site_links['University of Waterloo'] = 'https://uwaterloo.ca'; $site_links['Applied Health Sciences'] = 'https://uwaterloo.ca/applied-health-sciences/'; $site_links['Applied Health Sciences - Recreation and Leisure Studies'] = 'https://uwaterloo.ca/recreation-and-leisure-studies/'; $site_links['Applied Health Sciences - Kinesiology'] = 'https://uwaterloo.ca/kinesiology/'; $site_links['Applied Health Sciences - Public Health'] = 'https://uwaterloo.ca/public-health-and-health-systems/'; $site_links['Arts'] = 'https://uwaterloo.ca/arts/'; $site_links['Arts - Anthropology'] = 'https://uwaterloo.ca/anthropology/'; $site_links['Arts - Classical Studies'] = 'https://uwaterloo.ca/classical-studies/'; $site_links['Arts - Drama Speech Communication'] = 'https://uwaterloo.ca/drama-speech-communication/'; $site_links['Arts - Economics'] = 'https://uwaterloo.ca/economics/'; $site_links['Arts - English Language Literature'] = 'https://uwaterloo.ca/english/'; $site_links['Arts - Fine Arts'] = 'https://uwaterloo.ca/fine-arts/'; $site_links['Arts - French'] = 'https://uwaterloo.ca/french-studies/'; $site_links['Arts - Germanic Slavic Studies'] = 'https://uwaterloo.ca/germanic-slavic-studies/'; $site_links['Arts - History'] = 'https://uwaterloo.ca/history/'; $site_links['Arts - Philosophy'] = 'https://uwaterloo.ca/philosophy/'; $site_links['Arts - Political Science'] = 'https://uwaterloo.ca/political-science/'; $site_links['Arts - Psychology'] = 'https://uwaterloo.ca/psychology/'; $site_links['Arts - Religious Studies'] = 'https://uwaterloo.ca/religious-studies/'; $site_links['Arts - School of Accounting and Finance'] = 'https://uwaterloo.ca/school-of-accounting-and-finance/'; $site_links['Arts - Sociology and Legal Studies'] = 'https://uwaterloo.ca/sociology-and-legal-studies/'; $site_links['Arts - Spanish and Latin American Studies'] = 'https://uwaterloo.ca/spanish/'; $site_links['Engineering'] = 'https://uwaterloo.ca/engineering/'; $site_links['Engineering wordmark'] = 'https://uwaterloo.ca/engineering/'; $site_links['Engineering - Architecture'] = 'https://uwaterloo.ca/architecture/'; $site_links['Engineering - Chemical Engineering'] = 'https://uwaterloo.ca/chemical-engineering/'; $site_links['Engineering - Civil Environmental Engineering'] = 'https://uwaterloo.ca/civil-environmental-engineering/'; $site_links['Engineering - Electrical Computer Engineering'] = 'https://uwaterloo.ca/electrical-computer-engineering/'; $site_links['Engineering - Management Sciences'] = 'https://uwaterloo.ca/management-sciences/'; $site_links['Engineering - Mechanical Engineering'] = 'https://uwaterloo.ca/mechanical-mechatronics-engineering/'; $site_links['Engineering - Systems Design Engineering'] = 'https://uwaterloo.ca/systems-design-engineering/'; $site_links['Environment'] = 'https://uwaterloo.ca/environment/'; $site_links['Environment - Environment Enterprise Development'] = 'https://uwaterloo.ca/school-environment-enterprise-development/'; $site_links['Environment - Enviromental Resources and Sustainability'] = 'https://uwaterloo.ca/environment-resources-and-sustainability/'; $site_links['Environment - Geography Environmental and Management'] = 'https://uwaterloo.ca/geography-environmental-management/'; $site_links['Environment - Knowledge Intergration'] = 'https://uwaterloo.ca/knowledge-integration/'; $site_links['Environment - Planning'] = 'https://uwaterloo.ca/planning/'; $site_links['Mathematics'] = 'https://uwaterloo.ca/math/'; $site_links['Mathematics - Applied Math'] = 'https://uwaterloo.ca/applied-mathematics/'; $site_links['Mathematics - Combinatorics and Optimization'] = 'https://uwaterloo.ca/combinatorics-and-optimization/'; $site_links['Mathematics - Computer Science'] = 'https://cs.uwaterloo.ca/'; $site_links['Mathematics - Pure Math'] = 'https://uwaterloo.ca/pure-mathematics/'; $site_links['Mathematics - Statistics Actuarial Science'] = 'https://uwaterloo.ca/statistics-and-actuarial-science/'; $site_links['Science'] = 'https://uwaterloo.ca/science/'; $site_links['Sciecne - Pharmacy'] = 'https://uwaterloo.ca/pharmacy/'; $site_links['Science - Biology'] = 'https://uwaterloo.ca/biology/'; $site_links['Science - Chemistry'] = 'https://uwaterloo.ca/chemistry/'; $site_links['Science- Earth and Environmental Science'] = 'https://uwaterloo.ca/earth-environmental-sciences/'; $site_links['Science - Optometry and Vision Science'] = 'https://uwaterloo.ca/optometry-vision-science/'; $site_links['Science - Physics and Astronomy'] = 'https://uwaterloo.ca/physics-astronomy/'; $site_links['Conrad Grebel'] = 'https://uwaterloo.ca/grebel/'; $site_links['Renison University College'] = 'https://uwaterloo.ca/renison/'; $site_links['St. Jerome\'s University'] = 'https://www.sju.ca/'; $site_links['St. Jerome\'s University'] = 'https://www.sju.ca/'; $site_links['St. Paul\'s University College'] = 'https://uwaterloo.ca/stpauls/'; $site_links['McMaster University'] = 'http://www.mcmaster.ca/'; $site_links['University of Guelph'] = 'http://www.uoguelph.ca/'; $site_links['Water Institute'] = 'https://uwaterloo.ca/water-institute/'; $site_links['Western University'] = 'http://www.uwo.ca/'; $site_links['Wilfrid Laurier University'] = 'https://www.wlu.ca/'; return $site_links; }