You are here

function ds_extras_switch_view_mode_field in Display Suite 7.2

Same name and namespace in other branches
  1. 7 modules/ds_extras/ds_extras.module \ds_extras_switch_view_mode_field()

Switch view mode field.

1 string reference to 'ds_extras_switch_view_mode_field'
ds_extras_ds_fields_info in modules/ds_extras/ds_extras.ds_fields_info.inc
Implements hook_ds_fields_info().

File

modules/ds_extras/ds_extras.module, line 307
Display Suite extras main functions.

Code

function ds_extras_switch_view_mode_field($field) {
  $output = '';
  static $added = FALSE;
  if (isset($field['formatter_settings'])) {
    $entity = $field['entity'];
    $id = $entity->nid;
    $url = $field['entity_type'] . '-' . $field['view_mode'] . '-' . $id . '-';
    $switch = array();
    foreach ($field['formatter_settings']['vms'] as $key => $value) {
      if (!empty($value)) {
        $class = 'switch-' . $key;
        if ($key == $field['view_mode']) {
          $switch[] = '<span class="' . $class . '">' . check_plain(t($value)) . '</span>';
        }
        else {
          $switch[] = '<span class="' . $class . '"><a href="" class="' . $url . $key . '">' . check_plain(t($value)) . '</a></span>';
        }
      }
    }
    if (!empty($switch)) {
      if (!$added) {
        $add = TRUE;
        drupal_add_js(drupal_get_path('module', 'ds_extras') . '/js/ds_extras.js');
      }
      $output = '<div class="switch-view-mode-field">' . implode(' ', $switch) . '</div>';
    }
  }
  return $output;
}