You are here

function ds_get_layout in Display Suite 7

Same name and namespace in other branches
  1. 6.3 ds.module \ds_get_layout()
  2. 7.2 ds.module \ds_get_layout()

Get a layout for a given entity.

Parameters

$entity_type: The name of the entity.

$bundle: The name of the bundle.

$view_mode: The name of the view mode.

$fallback: Whether to fallback to default or not.

Return value

$layout Array of layout variables for the regions.

17 calls to ds_get_layout()
ds_entity_variables in ./ds.module
Add variables to an entity.
ds_extras_contextual_links_view_alter in modules/ds_extras/ds_extras.module
Implements hook_contextual_links_view_alter().
ds_extras_contextual_page_tab in modules/ds_extras/ds_extras.pages.inc
Menu callback: redirect to manage display.
ds_extras_entity_view_alter in modules/ds_extras/ds_extras.module
Implements hook_entity_view_alter().
ds_extras_field_attach_view_alter in modules/ds_extras/ds_extras.module
Implements hook_field_attach_view_alter().

... See full list

File

./ds.module, line 477
Display Suite core functions.

Code

function ds_get_layout($entity_type, $bundle, $view_mode, $fallback = TRUE) {
  static $layouts = array();
  $layout_key = $entity_type . '_' . $bundle . '_' . $view_mode;
  if (!isset($layouts[$layout_key])) {
    $entity_info = entity_get_info();
    $overriden = TRUE;
    if ($view_mode != 'form') {
      $view_mode_settings = field_view_mode_settings($entity_type, $bundle);
      $overriden = !empty($view_mode_settings[$view_mode]['custom_settings']) ? TRUE : FALSE;
    }

    // Check if a layout is configured.
    if (isset($entity_info[$entity_type]['bundles'][$bundle]['layouts'][$view_mode]) && ($overriden || $view_mode == 'default')) {
      $layouts[$layout_key] = $entity_info[$entity_type]['bundles'][$bundle]['layouts'][$view_mode];
      $layouts[$layout_key]['view_mode'] = $view_mode;
    }

    // In case $view_mode is not found, check if we have a default layout,
    // but only if the view mode settings aren't overridden for this view mode.
    if ($view_mode != 'default' && !$overriden && $fallback && isset($entity_info[$entity_type]['bundles'][$bundle]['layouts']['default'])) {
      $layouts[$layout_key] = $entity_info[$entity_type]['bundles'][$bundle]['layouts']['default'];
      $layouts[$layout_key]['view_mode'] = 'default';
    }

    // Register the false return value as well.
    if (!isset($layouts[$layout_key])) {
      $layouts[$layout_key] = FALSE;
    }
  }
  return $layouts[$layout_key];
}