Commit e70c57b9 authored by Eric Bremner's avatar Eric Bremner
Browse files

ISTWCMS-4980: adding code and update hooks to use site footer apis

parent 3405f2b0
...@@ -110,70 +110,8 @@ function uw_virtual_site_homepage_field_default_field_bases() { ...@@ -110,70 +110,8 @@ function uw_virtual_site_homepage_field_default_field_bases() {
'locked' => 0, 'locked' => 0,
'module' => 'list', 'module' => 'list',
'settings' => array( 'settings' => array(
'allowed_values' => array( 'allowed_values' => array(),
1 => 'Site name (no logo)', 'allowed_values_function' => '_uw_virtual_site_homepage_site_footer_allowed_values()',
'logo' => 'University of Waterloo',
'ahs' => 'Applied Health Sciences',
'ahs_Kinesiology' => 'Applied Health Sciences - Kinesiology',
'ahs_PublicHealth' => 'Applied Health Sciences - Public Health',
'ahs_Recreation_Lesiure' => 'Applied Health Sciences - Recreation and Leisure Studies',
'Arts' => 'Arts',
'Arts_Anthropology' => 'Arts - Anthropology',
'Arts_Classical_Studies' => 'Arts - Classical Studies',
'Arts_Drama_Speech_Communication' => 'Arts - Drama Speech Communication',
'Arts_Economics' => 'Arts - Economics',
'Arts_English_Language_Literature' => 'Arts - English Language Literature',
'Arts_FineArts' => 'Arts - Fine Arts',
'Arts_French' => 'Arts - French',
'Arts_Germanic_Slavic_Studies' => 'Arts - Germanic Slavic Studies',
'Arts_History' => 'Arts - History',
'Arts_Philosophy' => 'Arts - Philosophy',
'Arts_Political_Science' => 'Arts - Political Science',
'Arts_Psychology' => 'Arts - Psychology',
'Arts_Religious_Studies' => 'Arts - Religious Studies',
'Arts_School_of_Accounting_and_Finance' => 'Arts - School of Accounting and Finance',
'Arts_Sociology_and_Legal_Studies' => 'Arts - Sociology and Legal Studies',
'Arts_Spanish_and_Latin_American_Studies' => 'Arts - Spanish and Latin American Studies',
'Engineering' => 'Engineering',
'Engineering_wordmark' => 'Engineering wordmark',
'Engineering_Architecture' => 'Engineering - Architecture',
'Engineering_Chemical_Engineering' => 'Engineering - Chemical Engineering',
'Engineering_Civil_Environmental_Engineering' => 'Engineering - Civil Environmental Engineering',
'Engineering_Electrical_Computer_Engineering' => 'Engineering - Electrical Computer Engineering',
'Engineering_Management_Sciences' => 'Engineering - Management Sciences',
'Engineering_Mechanical_Engineering' => 'Engineering - Mechanical Engineering',
'Engineering_Systems_Design_Engineering' => 'Engineering - Systems Design Engineering',
'Environment' => 'Environment',
'Environment_Environment_Enterprise_Development' => 'Environment - Environment Enterprise Development',
'Environment_Enviromental_Resources_and_Sustainability' => 'Environment - Enviromental Resources and Sustainability',
'Environment_Geography_Environmental_and_Management' => 'Environment - Geography Environmental and Management',
'Environment_Knowledge_Intergration' => 'Environment - Knowledge Intergration',
'Environment_Planning' => 'Environment - Planning',
'Mathematics' => 'Mathematics',
'Math_Applied_Math' => 'Mathematics - Applied Math',
'Math_Combinatorics_and_Optimization' => 'Mathematics - Combinatorics and Optimization',
'Math_Computer_Science' => 'Mathematics - Computer Science',
'Math_Pure_Math' => 'Mathematics - Pure Math',
'Math_Statistics_Actuarial_Science' => 'Mathematics - Statistics Actuarial Science',
'Science' => 'Science',
'Science_Biology' => 'Science - Biology',
'Science_Chemistry' => 'Science - Chemistry',
'Science_Earth_and_Environmental_Science' => 'Science - Earth and Environmental Science',
'Science_Optometry_and_Vision_Science' => 'Science - Optometry and Vision Science',
'Sciecne_Pharmacy' => 'Science - Pharmacy',
'Science_Physics_and_Astronomy' => 'Science - Physics and Astronomy',
'conrad_grebel' => 'Conrad Grebel',
'renison_university_college' => 'Renison University College',
'st_jeromes_university' => 'St. Jerome’s University',
'st_pauls' => 'St. Paul’s University College',
'McMaster_University' => 'McMaster University',
'University_of_Guelph' => 'University of Guelph',
'Water_Institute' => 'Water Institute',
'Western_University' => 'Western University',
'Wilfrid_Laurier_University' => 'Wilfrid Laurier University',
'Other' => 'Other',
),
'allowed_values_function' => '',
), ),
'translatable' => 0, 'translatable' => 0,
'type' => 'list_text', 'type' => 'list_text',
......
...@@ -286,6 +286,30 @@ function uw_virtual_site_homepage_update_7103() { ...@@ -286,6 +286,30 @@ function uw_virtual_site_homepage_update_7103() {
features_revert_module('uw_virtual_site_homepage'); features_revert_module('uw_virtual_site_homepage');
} }
/**
* Implements hook_update_N().
*
* Update to use site footer logos from brand site.
*/
function uw_virtual_site_homepage_update_7104() {
// Set defaults for api variables.
variable_set('uw_site_footer_api_version', '1.0');
variable_set('uw_site_footer_api_server', 'uwaterloo.ca');
variable_set('uw_site_footer_api_site', 'brand');
variable_set('uw_site_footer_ignore_certificates', 0);
// Get the faculty list logo field.
$field = field_info_field('field_uw_faculty_list_logo');
// Update the settings.
$field['settings']['allowed_values_function'] = '_uw_virtual_site_homepage_site_footer_allowed_values';
$field['settings']['allowed_values'] = array();
// Save the field.
field_update_field($field);
}
/** /**
* Helper function to get the value from field_uw_faculty. * Helper function to get the value from field_uw_faculty.
*/ */
......
...@@ -146,6 +146,7 @@ function uw_virtual_site_homepage_image_field_widget_process($element, &$form_st ...@@ -146,6 +146,7 @@ function uw_virtual_site_homepage_image_field_widget_process($element, &$form_st
* Placing homepage banners on the virtual site homepage. * Placing homepage banners on the virtual site homepage.
*/ */
function uw_virtual_site_homepage_page_alter(&$page) { function uw_virtual_site_homepage_page_alter(&$page) {
global $base_path; global $base_path;
// Setting the variables to be used in homepage banners. // Setting the variables to be used in homepage banners.
...@@ -323,6 +324,27 @@ function uw_virtual_site_homepage_page_alter(&$page) { ...@@ -323,6 +324,27 @@ function uw_virtual_site_homepage_page_alter(&$page) {
*/ */
function uw_virtual_site_homepage_form_alter(&$form, &$form_state, $form_id) { function uw_virtual_site_homepage_form_alter(&$form, &$form_state, $form_id) {
// Set the options for the faculty logo.
if ($form_id=='uw_virtual_site_homepage_node_form') {
// Load the node, so that we can get the faculty logo.
if (arg(0) == 'node' && is_numeric(arg(1))) {
// Get the nid
$nid = arg(1);
// Load the node if you need to
$node = node_load($nid);
}
// Set the default value if there is one.
if (isset($node->field_uw_faculty_list_logo['und'][0]['value'])) {
$form['field_uw_faculty_list_logo'][LANGUAGE_NONE]['#default_value'] = $node->field_uw_faculty_list_logo['und'][0]['value'];
}
// Set the options to the ones from the brand site.
$form['field_uw_faculty_list_logo'][LANGUAGE_NONE]['#options'] = _uw_virtual_site_homepage_site_footer_allowed_values();
}
if ($form_id == "biblio_search_form") { if ($form_id == "biblio_search_form") {
$form['search_form']['#collapsed'] = FALSE; $form['search_form']['#collapsed'] = FALSE;
$form['search_form']['#collapsible'] = FALSE; $form['search_form']['#collapsible'] = FALSE;
...@@ -518,6 +540,174 @@ function uw_virtual_site_homepage_node_form_redirect($form, &$form_state) { ...@@ -518,6 +540,174 @@ function uw_virtual_site_homepage_node_form_redirect($form, &$form_state) {
$form_state['redirect'] = 'home'; $form_state['redirect'] = 'home';
} }
/**
* Helper function.
*
* Set the allowed values for the site footer logo.
*/
function _uw_virtual_site_homepage_site_footer_allowed_values() {
// Get all the site footer logos from the API.
$json = _uw_virtual_site_homepage_get_request('uw-logos-site-footers');
if (!$json || isset($json['status']) && $json['status'] == '404') {
$options = array(0 => 'Site name (no logo)');
return $options;
}
else {
// Step through each response and set the options.
foreach ($json as $data) {
// Set the option value based on title and faculty.
if (isset($data['faculty']) && $data['faculty'] !== '' && $data['type_of_logo'] !== 'Faculty') {
$options[$data['nid']] = $data['title'] . ' (' . $data['faculty'] . ')';
}
else {
$options[$data['nid']] = $data['title'];
}
}
// Initial blank option.
$options = array(0 => 'Site name (no logo)') + $options;
return $options;
}
}
/**
* Helper function.
*
* Get the request from the api site.
*/
function _uw_virtual_site_homepage_get_request($remote_url, $query_parameters = NULL) {
// Get the api site server from settings.
$api_site_server = variable_get('uw_site_footer_api_server');
// Get the central site URL from settings.
$api_site_url = variable_get('uw_site_footer_api_site');
// Get the api version from settings.
$api_version = variable_get('uw_site_footer_api_version');
// Set the URL based on the settings.
$url = 'https://' . $api_site_server . '/' . $api_site_url . '/api/v' . $api_version . '/' . $remote_url;
// Set the URL with the parameters.
$url = url($url, array('query' => $query_parameters));
// Check if we should ignore certificates.
if (variable_get('uw_site_footer_ignore_certificates')) {
$context = stream_context_create(array(
'ssl' => array(
'verify_peer' => FALSE,
'verify_depth' => 5,
'allow_self_signed' => TRUE,
'verify_peer_name' => FALSE,
),
));
$options['context'] = $context;
}
else {
$options = array();
}
// Get the actual request.
$request = drupal_http_request($url, $options);
if (!isset($request->data)) {
return;
}
// Get the JSON data from the request.
$json_response = drupal_json_decode($request->data);
return $json_response;
}
/**
* Implements hook_menu().
*
* Add menu links for site footer settings.
*/
function uw_virtual_site_homepage_menu() {
// Array for the menu items.
$items = array();
$items['admin/config/system/uw_site_footer_settings'] = array(
'title' => 'Site footer settings',
'description' => 'General settings of site footer',
'page callback' => 'drupal_get_form',
'page arguments' => array('_uw_virtual_site_homepage_settings_form'),
'access arguments' => array('administer site footer'),
);
return $items;
}
/**
* Implements hook_permission().
*
* Add the permissions for site footer.
*/
function uw_virtual_site_homepage_permission() {
return array(
'administer site footer' => array(
'title' => t('Administer site footer'),
),
);
}
/**
* Helper function.
*
* Menu callback for important dates config form.
*/
function _uw_virtual_site_homepage_settings_form($form, &$form_state) {
// The API version for the site footer API.
$form['uw_site_footer_api_version'] = array(
'#type' => 'textfield',
'#title' => t('Site footer API version number'),
'#description' => t('Enter the API version number for site footer, i.e. 1.0, 1.1, 1.2, etc ...'),
'#default_value' => variable_get('uw_site_footer_api_version'),
'#required' => TRUE,
);
// The server for the site footer API.
$form['uw_site_footer_api_server'] = array(
'#type' => 'textfield',
'#title' => t('Site footer API server'),
'#description' => t('Enter the server address for the site footer API site, i.e. uwaterloo.ca, this is the text https://<site_footer_api_server>/university-relations'),
'#default_value' => variable_get('uw_site_footer_api_server'),
'#required' => TRUE,
);
// The URL for the site footer API.
$form['uw_site_footer_api_site'] = array(
'#type' => 'textfield',
'#title' => t('Site footer API site URL'),
'#description' => t('Enter the URL for the site footer API site. i.e. university-relations, this is the text: https://uwaterloo.ca/<site_footer_api_url>.'),
'#default_value' => variable_get('uw_site_footer_api_site'),
'#required' => TRUE,
);
// Check if certificates are to be ignored.
$form['uw_site_footer_ignore_certificates'] = array(
'#type' => 'checkbox',
'#title' => t('Ignore invalid certificates'),
'#default_value' => variable_get('uw_site_footer_ignore_certificates', 0),
'#description' => t('Ignore invalid certificates when connecting to site footer API'),
'#required' => FALSE,
);
return system_settings_form($form);
}
/** /**
* *
*/ */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment