You are here

single_page_site_next_page.module in Single Page Site 7

File

modules/single_page_site_next_page/single_page_site_next_page.module
View source
<?php

/**
 * Implements hook_single_page_site_alter_output().
 * @param type $output
 * @return type
 */
function single_page_site_next_page_single_page_site_output_alter(&$output, $current_item) {

  // Get menu items.
  $menu_items = single_page_site_next_page_get_single_page_items();
  $count_menu_items = count($menu_items);

  // If item is not last item.
  if ($current_item < $count_menu_items) {
    $menu_item = $menu_items[$current_item];

    // If next menu item doens't has class "hide" => Add scroll to next page link.
    if (empty($menu_item['#localized_options']['attributes']['class']) || !empty($menu_item['#localized_options']['attributes']['class']) && !in_array('hide', $menu_item['#localized_options']['attributes']['class'])) {
      $next_link = $menu_item['#href'];
      $anchor = _single_page_site_generate_anchor(drupal_get_path_alias($next_link));
      $output .= l(_single_page_site_get_title($menu_item), '', array(
        'fragment' => $anchor,
        'external' => TRUE,
        'attributes' => array(
          'class' => array(
            'to-next-page',
          ),
        ),
      ));
    }
  }
}

/**
 * Fetches single page items.
 * @return type
 */
function single_page_site_next_page_get_single_page_items() {
  $settings = variable_get('single_page_site_settings', array());
  $items = array();
  $menu_name = $settings['menu'];
  $tree = menu_tree($menu_name);
  foreach ($tree as $key => $item) {

    // Check if menu item has to be rendered.
    $render_menu_item = FALSE;
    if (is_numeric($key)) {
      if ($item['#href'] != '<front>') {
        if (empty($settings['class'])) {

          // If class is empty => all menu items.
          $render_menu_item = TRUE;
        }
        elseif (!empty($item['#title']) && !empty($item['#localized_options']['attributes']['class']) && in_array($settings['class'], $item['#localized_options']['attributes']['class'])) {

          // If class is filled out => Only menu items with class.
          $render_menu_item = TRUE;
        }
      }
    }
    if ($render_menu_item) {
      $items[] = $item;
    }
  }
  return $items;
}

Functions

Namesort descending Description
single_page_site_next_page_get_single_page_items Fetches single page items.
single_page_site_next_page_single_page_site_output_alter Implements hook_single_page_site_alter_output().