You are here

function ds_switch_view_mode_inline in Display Suite 7.2

Same name and namespace in other branches
  1. 7 modules/ds_extras/ds_extras.pages.inc \ds_switch_view_mode_inline()

Menu callback: switches to another view mode inline.

1 string reference to 'ds_switch_view_mode_inline'
ds_extras_menu in modules/ds_extras/ds_extras.module
Implements hook_menu().

File

modules/ds_extras/includes/ds_extras.pages.inc, line 56
Display Suite Extras page functions.

Code

function ds_switch_view_mode_inline() {
  $content = '';
  $status = TRUE;
  $error = FALSE;
  $id = $_REQUEST['id'];
  $view_mode = $_REQUEST['view_mode'];
  $entity_type = $_REQUEST['entity_type'];
  $entity = entity_load($entity_type, array(
    $id,
  ));
  if (!isset($entity[$id])) {
    $status = FALSE;
    $error = t('Content was not found.');
  }
  else {
    if (node_access('view', $entity[$id])) {
      $element = node_view($entity[$id], $view_mode);
      $content = drupal_render($element);
    }
    else {
      $error = t('Access denied');
    }
  }
  drupal_add_http_header('Content-Type', 'text/javascript; charset=utf-8');
  print drupal_json_encode(array(
    'status' => $status,
    'content' => $content,
    'errorMessage' => $error,
  ));
  exit;
}