You are here

public function DisplayHelper::getPreferredMode in Lightning Core 8

Same name and namespace in other branches
  1. 8.5 src/DisplayHelper.php \Drupal\lightning_core\DisplayHelper::getPreferredMode()
  2. 8.2 src/DisplayHelper.php \Drupal\lightning_core\DisplayHelper::getPreferredMode()
  3. 8.3 src/DisplayHelper.php \Drupal\lightning_core\DisplayHelper::getPreferredMode()
  4. 8.4 src/DisplayHelper.php \Drupal\lightning_core\DisplayHelper::getPreferredMode()

Returns the first available preferred view mode.

Parameters

string $entity_type: The entity type ID.

string $bundle: The bundle.

string[] $preferences: The view mode IDs to check, in descending order of preference.

Return value

string The first preferred view mode ID that has a view display associated with it. If there are none, falls back to the default view mode.

File

src/DisplayHelper.php, line 55

Class

DisplayHelper
Helps query and configure various display settings.

Namespace

Drupal\lightning_core

Code

public function getPreferredMode($entity_type, $bundle, array $preferences) {
  $displays = $this->queryFactory
    ->get('entity_view_display')
    ->execute();
  foreach ($preferences as $view_mode) {
    if (in_array($entity_type . '.' . $bundle . '.' . $view_mode, $displays)) {
      return $view_mode;
    }
  }
  return 'default';
}