Skip to content

Instantly share code, notes, and snippets.

@labboy0276
Created August 26, 2014 19:25
Show Gist options
  • Save labboy0276/439d1c845ee56388e161 to your computer and use it in GitHub Desktop.
Save labboy0276/439d1c845ee56388e161 to your computer and use it in GitHub Desktop.
Adds Variant for Panels
<?php
/**
* Implements hook_entity_info_alter().
*/
function panelizer_variant_entity_info_alter(&$entity_info) {
$entity_info['node']['view modes']['doctoral_programs'] = array(
'label' => t('Doctoral Programs'),
'custom settings' => TRUE,
);
$entity_info['node']['view modes']['ms_minors'] = array(
'label' => t('MS Minors'),
'custom settings' => TRUE,
);
$entity_info['node']['view modes']['ms_program'] = array(
'label' => t('MS Program'),
'custom settings' => TRUE,
);
$entity_info['node']['view modes']['ms_specialty_area'] = array(
'label' => t('MS Specialty Area'),
'custom settings' => TRUE,
);
$entity_info['node']['view modes']['special_studies'] = array(
'label' => t('Special Studies'),
'custom settings' => TRUE,
);
}
/**
* Implements hook_entity_view_mode_alter().
*/
function panelizer_variant_entity_view_mode_alter(&$view_mode, $context) {
if ($context['entity']->type == 'academic_programs') {
$taxonomy_term = $context['entity']->field_ap_program['und'][0]['taxonomy_term']->name;
switch($taxonomy_term) {
case 'MS Minors':
$view_mode = 'ms_minors';
break;
case 'Doctoral Programs':
$view_mode = 'doctoral_programs';
break;
case 'MS Program':
$view_mode = 'ms_program';
break;
case 'MS Specialty Area':
$view_mode = 'ms_specialty_area';
break;
case 'Special Studies':
$view_mode = 'special_studies';
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment