You are here

function _ds_entity_info_alter in Display Suite 7

Same name and namespace in other branches
  1. 7.2 includes/ds.registry.inc \_ds_entity_info_alter()

Implements hook_entity_info_alter().

1 call to _ds_entity_info_alter()
ds_entity_info_alter in ./ds.module
Implements hook_entity_info_alter().

File

./ds.registry.inc, line 155
Registry file for Display Suite.

Code

function _ds_entity_info_alter(&$entity_info) {

  // Make sure ds_view_modes table exists.
  if (!db_table_exists('ds_view_modes')) {
    return;
  }
  ctools_include('export');

  // Add custom view modes to entities.
  $custom_view_modes = ctools_export_crud_load_all('ds_view_modes');
  foreach ($custom_view_modes as $view_mode_key => $view_mode_value) {
    $view_mode = array(
      'label' => check_plain($view_mode_value->label),
      'custom settings' => FALSE,
    );
    foreach ($view_mode_value->entities as $entity_type) {
      if (isset($entity_info[$entity_type])) {
        $entity_info[$entity_type]['view modes'][$view_mode_key] = $view_mode;
      }
    }
  }

  // Add layout if applicable.
  $ds_layouts = ds_get_layout_info();
  $ds_layout_settings = ctools_export_crud_load_all('ds_layout_settings');
  foreach ($ds_layout_settings as $row) {

    // Don't store any configurations with layouts that don't exist anymore.
    if (!isset($ds_layouts[$row->layout]) && !isset($row->settings['ds_panels'])) {
      continue;
    }
    if (!isset($entity_info[$row->entity_type])) {
      continue;
    }
    if (!isset($entity_info[$row->entity_type]['bundles'][$row->bundle])) {
      continue;
    }
    $layout = array();
    if (!isset($row->settings['ds_panels'])) {
      $layout = $ds_layouts[$row->layout];
    }
    $layout['layout'] = $row->layout;
    $layout['settings'] = $row->settings;
    $entity_info[$row->entity_type]['bundles'][$row->bundle]['layouts'][$row->view_mode] = $layout;
  }
}