You are here

public static function EntityHelper::getViewModeOptions in Helper 7

File

lib/EntityHelper.php, line 411

Class

EntityHelper

Code

public static function getViewModeOptions($entity_type, $bundle = NULL, $include_disabled = TRUE) {
  $view_modes = array();
  $info = entity_get_info($entity_type);
  if (!empty($info['fieldable'])) {
    $view_modes['default'] = t('Default');
  }
  if (!empty($info['view modes'])) {
    $view_modes += ArrayHelper::extractNestedValuesToArray($info['view modes'], array(
      'label',
    ));
  }

  // Filter out disabled view modes if requested, and a bundle was provided.
  if (isset($bundle) && !$include_disabled) {
    $view_mode_settings = field_view_mode_settings($entity_type, $bundle);
    foreach ($view_modes as $view_mode => $label) {
      if (empty($view_mode_settings[$view_mode]['custom_settings'])) {
        unset($view_modes[$view_mode]);
      }
    }
  }
  return $view_modes;
}