View source
<?php
function view_modes_display_menu() {
$items = array();
$items['node/%node/preview'] = array(
'title' => 'Preview display',
'description' => 'Preview display of this content in the enabled view modes.',
'page callback' => 'view_modes_display_preview_entity',
'page arguments' => array(
1,
'node',
),
'file' => 'view_modes_display.pages.inc',
'access arguments' => array(
'preview view modes',
),
'type' => MENU_LOCAL_TASK,
);
$items['user/%user/preview'] = array(
'title' => 'Preview display',
'description' => 'Preview display of this user profile.',
'page callback' => 'view_modes_display_preview_entity',
'page arguments' => array(
1,
'user',
),
'file' => 'view_modes_display.pages.inc',
'access arguments' => array(
'preview view modes',
),
'type' => MENU_LOCAL_TASK,
);
if (module_exists('taxonomy')) {
$items['taxonomy/term/%taxonomy_term/preview'] = array(
'title' => 'Preview display',
'description' => 'Preview display of this term.',
'page callback' => 'view_modes_display_preview_entity',
'page arguments' => array(
2,
'taxonomy_term',
),
'access arguments' => array(
'preview view modes',
),
'file' => 'view_modes_display.pages.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 12,
);
}
if (module_exists('profile2_page')) {
foreach (profile2_get_types() as $type_name => $type) {
if (!empty($type->data['use_page'])) {
$path = profile2_page_get_base_path($type);
$count = count(explode('/', $path));
$items[$path . '/%profile2_by_uid/preview'] = array(
'title' => 'Preview display',
'description' => 'Preview display of this profile2.',
'page callback' => 'view_modes_display_preview_entity',
'page arguments' => array(
$count,
'profile2',
),
'access callback' => 'profile2_access',
'access arguments' => array(
'edit',
$count,
),
'file' => 'view_modes_display.pages.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 12,
);
}
}
}
return $items;
}
function view_modes_display_permission() {
return array(
'preview view modes' => array(
'title' => t('Peview entities in all available view modes'),
'description' => t('Allows users to preview an entity in all available view modes on a page.'),
),
);
}
function view_modes_display_contextual_links_view_alter(&$element, $items) {
if (!empty($element['#element']['#entity_type']) && !empty($element['#element']['#bundle']) && !empty($element['#element']['#node']) && user_access('administer content types')) {
$entity_type = $element['#element']['#entity_type'];
$bundle = $element['#element']['#bundle'];
$view_mode = isset($element['#element']['#view_mode']) ? $element['#element']['#view_mode'] : 'default';
$preview_path = 'node/' . $element['#element']['#node']->nid . '/preview';
$view_mode_settings = field_view_mode_settings($entity_type, $bundle);
$overridden = !empty($view_mode_settings[$view_mode]['custom_settings']) ? TRUE : FALSE;
$element['#links']['preview-display'] = array(
'title' => t('Preview display'),
'href' => $preview_path,
'query' => drupal_get_destination(),
);
}
}