You are here

private function EntityReferenceDisplayItem::getAllDisplayModes in Entity Reference Display 8

Get all display modes in alphabetical order with Default as first.

2 calls to EntityReferenceDisplayItem::getAllDisplayModes()
EntityReferenceDisplayItem::fieldSettingsForm in src/Plugin/Field/FieldType/EntityReferenceDisplayItem.php
Returns a form for the field-level settings.
EntityReferenceDisplayItem::getPossibleOptions in src/Plugin/Field/FieldType/EntityReferenceDisplayItem.php
Returns an array of possible values with labels for display.

File

src/Plugin/Field/FieldType/EntityReferenceDisplayItem.php, line 142

Class

EntityReferenceDisplayItem
Plugin implementation of the 'entity_reference_display' field type.

Namespace

Drupal\entity_reference_display\Plugin\Field\FieldType

Code

private function getAllDisplayModes() {

  // Get all display modes grouped by entity types.
  $display_modes = \Drupal::service('entity_display.repository')
    ->getAllViewModes();

  // Get basic information about display modes.
  $result = [];
  foreach ($display_modes as $modes) {
    foreach ($modes as $mode => $info) {

      // If display mode is not already in result set.
      if (!isset($result[$mode])) {
        $result[$mode] = $info['label'];
      }
    }
  }

  // Sort display modes in alphabetical order.
  asort($result);

  // Return array of all display modes prepended by Default.
  return [
    'default' => 'Default',
  ] + $result;
}