diff --git a/bg_image_ui/README.txt b/bg_image_ui/README.txt index 3a35ed6..4033221 100644 --- a/bg_image_ui/README.txt +++ b/bg_image_ui/README.txt @@ -45,3 +45,5 @@ In the case that two paths overlap (for example, an item with the path "node/*" and another one with the path "node/1") the item appearing higher in the list will take precedence. The table is draggable to allow for easy sorting of items. + +If a path includes a link diff --git a/bg_image_ui/bg_image_ui.install b/bg_image_ui/bg_image_ui.install index e8b1d73..bf66c4e 100644 --- a/bg_image_ui/bg_image_ui.install +++ b/bg_image_ui/bg_image_ui.install @@ -25,6 +25,11 @@ function bg_image_ui_schema() { 'not null' => TRUE, 'default' => 0, ), + 'link' => array( + 'description' => 'The URL to link the image to', + 'type' => 'varchar', + 'length' => 255, + ), 'weight' => array( 'description' => 'The weight of the item in the list', 'type' => 'int', @@ -43,6 +48,18 @@ function bg_image_ui_install() { } /** + * Add link field to background image DB schema. + */ +function bg_image_ui_update_7000() { + $link = array( + 'description' => 'The URL to link the image to', + 'type' => 'varchar', + 'length' => 255, + ); + db_add_field('bg_image_paths', 'link', $link); +} + +/** * Implements hook_uninstall() */ function bg_image_ui_uninstall() { diff --git a/bg_image_ui/bg_image_ui.module b/bg_image_ui/bg_image_ui.module index ec30efe..829aed4 100644 --- a/bg_image_ui/bg_image_ui.module +++ b/bg_image_ui/bg_image_ui.module @@ -57,13 +57,30 @@ function bg_image_ui_theme() { } /** - * Implements hook_init() + * Implements hook_page_build(). */ -function bg_image_ui_init() { - $nid = bg_image_ui_page_has_bg_image(); - // Apply the background image if the nid is not FALSE - if ($nid !== FALSE) { - bg_image_add_background_image_from_node($nid); +function bg_image_ui_page_build(&$page) { + + $item = bg_image_ui_page_has_bg_image(); + if (!empty($item)) { + // If the page has a background image, add it. + bg_image_add_background_image_from_node($item->nid); + + // If the item has a link, add the link to page_top. + if (!bg_image_is_excluded() && !empty($item->link)) { + $options = array( + 'attributes' => array( + 'target' => '_blank', + 'style' => 'position: fixed; top: 0; left: 0; display: block; width: 100%; height: 100%; z-index:0;', + ), + ); + + $link = l('', $item->link, $options); + + $page['page_top']['takeover'] = array( + '#markup' => $link, + ); + } } } @@ -112,6 +129,10 @@ function bg_image_ui_paths_form($form, &$form_state) { '#options' => $node_options, '#default_value' => $item->nid, ); + $form['items'][$pid]['link'] = array( + '#type' => 'textfield', + '#default_value' => $item->link, + ); $form['items'][$pid]['remove'] = array( '#markup' => l(t('remove'), "admin/content/background-images/path/remove/$pid") ); @@ -137,6 +158,9 @@ function bg_image_ui_paths_form($form, &$form_state) { '#options' => array('' => ' - Select - ') + $node_options, '#default_value' => '', ); + $form['items'][0]['link'] = array( + '#type' => 'textfield', + ); $form['items'][0]['remove'] = array( '#value' => '', ); @@ -171,10 +195,11 @@ function bg_image_ui_paths_form_submit($form, &$form_state) { unset($form_state['values']['items'][0]); // Process the rest foreach ($form_state['values']['items'] as $pid => $item) { - // // If anything has changed... + // If anything has changed... if ($form['items'][$pid]['weight']['#default_value'] != $item['weight'] || - $form['items'][$pid]['path']['#default_value'] != $item['path'] || - $form['items'][$pid]['nid']['#default_value'] != $item['nid']) { + $form['items'][$pid]['path']['#default_value'] != $item['path'] || + $form['items'][$pid]['link']['#default_value'] != $item['link'] || + $form['items'][$pid]['nid']['#default_value'] != $item['nid']) { $item['pid'] = $pid; if ($pid == 0) { drupal_write_record('bg_image_paths', $item); @@ -191,11 +216,10 @@ function bg_image_ui_paths_form_submit($form, &$form_state) { * Theme the background image paths form into a table */ function theme_bg_image_ui_paths_table($args) { - //dpm($args); drupal_add_css(drupal_get_path('module', 'bg_image_ui') . '/css/bg_image_ui.css'); $form = $args['form']; $rows = array(); - $header = array('Path', 'Background Image Node', 'Preview', 'Remove', 'Weight'); + $header = array('Path', 'Background Image Node', 'Link', 'Preview', 'Remove', 'Weight'); $output = drupal_render($form['description']); foreach (element_children($form['items']) as $key) { $form['items'][$key]['weight']['#attributes']['class'] = array('bg-image-path-weight'); @@ -215,6 +239,7 @@ function theme_bg_image_ui_paths_table($args) { $row = array(); $row[] = drupal_render($form['items'][$key]['path']); $row[] = drupal_render($form['items'][$key]['nid']); + $row[] = drupal_render($form['items'][$key]['link']); $row[] = $preview; $row[] = drupal_render($form['items'][$key]['remove']); $row[] = drupal_render($form['items'][$key]['weight']); @@ -318,15 +343,15 @@ function bg_image_ui_remove_path_item($pid) { /** * Checks if the current path has a background image. - * If it does, we return the nid of the matching path - * or pattern. Othewise return false. + * If it does, we return the database row for the matching path + * or pattern. Otherwise return false. */ function bg_image_ui_page_has_bg_image() { $current_path_alias = drupal_get_path_alias($_GET['q']); $current_path = $_GET['q']; - foreach (bg_image_ui_get_paths() as $pid => $item) { + foreach (bg_image_ui_get_paths() as $item) { if (drupal_match_path($current_path, $item->path) || drupal_match_path($current_path_alias, $item->path)) { - return $item->nid; + return $item; } } return FALSE;