I have below code coming from External Link module in Drupal 7:
/**
* Implements hook_page_build().
*/
function extlink_page_build() {
$path = drupal_get_path('module', 'extlink');
drupal_add_js($path .'/extlink.js', array('every_page' => TRUE));
drupal_add_js(array('extlink' => array(
'extTarget' => variable_get('extlink_target', 0),
'extClass' => variable_get('extlink_class', 'ext'),
'extLabel' => check_plain(variable_get('extlink_label', t('(link is external)'))),
'extImgClass' => variable_get('extlink_img_class', 0),
'extSubdomains' => variable_get('extlink_subdomains', 1),
'extExclude' => variable_get('extlink_exclude', ''),
'extInclude' => variable_get('extlink_include', ''),
'extCssExclude' => variable_get('extlink_css_exclude', ''),
'extCssExplicit' => variable_get('extlink_css_explicit', ''),
'extAlert' => variable_get('extlink_alert', 0),
'extAlertText' => variable_get('extlink_alert_text', 'This link will take you to an external web site. We are not responsible for their content.'),
'mailtoClass' => variable_get('extlink_mailto_class', 'mailto'),
'mailtoLabel' => check_plain(variable_get('extlink_mailto_label', t('(link sends e-mail)'))),
)), 'setting');
}
I want to add below code from above function only if my some condition is true (which will be based on some user filed) , without overriding files of module it self:
drupal_add_js(array('extlink' => array(
'extTarget' => variable_get('extlink_target', 0),)), 'setting');
I am not getting any solution how to override this function thorough my custom module, Please suggest !
To make more clear I just want to add condition in above function so that js will only get added if condition according to user field is true.
UPDATE: I have tried like below code but its not working, please suggest what I am doing wrong My custom module name: custom_overrides
function custom_overrides_page_alter(&$page) {
global $user;
$userid = $user->uid;
if($userid){
$path = drupal_get_path('module', 'extlink');
drupal_add_js($path .'/extlink.js', array('every_page' => TRUE));
drupal_add_js(array('extlink' => array('extTarget' => variable_get('extlink_target', 0),)), 'setting');
}
}
Thanks!