You are here

public static function Ds::getDisplay in Display Suite 8.4

Same name and namespace in other branches
  1. 8.2 src/Ds.php \Drupal\ds\Ds::getDisplay()
  2. 8.3 src/Ds.php \Drupal\ds\Ds::getDisplay()

Gets a display for a given entity.

Parameters

string $entity_type: The name of the entity.

string $bundle: The name of the bundle.

string $view_mode: The name of the view mode.

bool $fallback: Whether to fallback to default or not.

Return value

array|bool The display.

3 calls to Ds::getDisplay()
ds_preprocess_field in ./ds.module
Implements hook_preprocess_field().
ds_switch_view_mode_form_node_form_alter in modules/ds_switch_view_mode/ds_switch_view_mode.module
Implements hook_form_BASE_FORM_ID_alter() for node_form.
ds_theme_suggestions_field_alter in ./ds.module
Implements hook_theme_suggestions_HOOK_alter().

File

src/Ds.php, line 140

Class

Ds
Helper class that holds all the main Display Suite helper functions.

Namespace

Drupal\ds

Code

public static function getDisplay($entity_type, $bundle, $view_mode, $fallback = TRUE) {

  /* @var $entity_display \Drupal\Core\Entity\Display\EntityDisplayInterface */
  $entity_manager = \Drupal::entityTypeManager();
  $entity_display = $entity_manager
    ->getStorage('entity_view_display')
    ->load($entity_type . '.' . $bundle . '.' . $view_mode);
  if ($entity_display) {
    $overridden = $entity_display
      ->status();
  }
  else {
    $overridden = FALSE;
  }
  if ($entity_display) {
    return $entity_display;
  }

  // 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' && !$overridden && $fallback) {

    /* @var $entity_default_display \Drupal\Core\Entity\Display\EntityDisplayInterface */
    $entity_manager = \Drupal::entityTypeManager();
    $entity_default_display = $entity_manager
      ->getStorage('entity_view_display')
      ->load($entity_type . '.' . $bundle . '.default');
    if ($entity_default_display) {
      return $entity_default_display;
    }
  }
  return FALSE;
}