You are here

function view_mode_page_menu_alter in View Mode Page 8.2

Same name and namespace in other branches
  1. 8 view_mode_page.module \view_mode_page_menu_alter()
  2. 7.2 view_mode_page.module \view_mode_page_menu_alter()
  3. 7 view_mode_page.module \view_mode_page_menu_alter()

Implements hook_menu_alter().

File

./view_mode_page.module, line 153
View Mode Page module allows users to add a page for a specific view mode.

Code

function view_mode_page_menu_alter(&$items) {

  // get the VMP patterns
  $page_definitions = view_mode_page_get_entity_patterns();

  // get the view modes in use
  $view_modes = view_mode_page_get_entity_view_modes();

  // hold mising view modes
  $missing_view_modes = array();

  // now add/alter menu items for each VMP page definition
  foreach ($page_definitions as $page) {
    $pattern = $page->url_pattern;
    $entity_type = $page->entity_type;
    $content_type = $page->content_type;
    $view_mode = $page->view_mode;
    $show_title = $page->show_title;
    $title = $page->title;

    // if there are no view modes for the entity type and something besides
    // default is requested, we should just skip
    if (!isset($view_modes[$entity_type]) && $view_mode != 'default') {
      $missing_view_modes[] = $page;
      continue;
    }

    // if this view mode is not in use, we shouldn't use it
    if (isset($view_modes[$entity_type]) && !in_array($view_mode, $view_modes[$entity_type]) && $view_mode != 'default') {
      $missing_view_modes[] = $page;
      continue;
    }

    // Define or redefine our page.
    $page = array();
    if (isset($items[$pattern])) {
      $page = $items[$pattern];
    }
    $page['page callback'] = 'view_mode_page_change_entity_view_mode';
    $page['page arguments'] = array(
      $entity_type,
      $content_type,
      $view_mode,
      $pattern,
      $show_title,
      $title,
    );
    if (!isset($page['access arguments'])) {
      $page['access arguments'] = array(
        'access content',
      );
    }
    $items[$pattern] = $page;
  }

  // set a variable for missing view modes
  if (count($missing_view_modes)) {
    variable_set('view_mode_page_missing_view_modes', $missing_view_modes);
  }
  else {
    variable_del('view_mode_page_missing_view_modes');
  }
}