You are here

public function ViewfieldItem::getDisplayOptions in Viewfield 8.3

Get display ID options for a view.

Parameters

string $entity_id: The entity_id of the view.

bool $filter: (optional) Flag to filter the output using the 'allowed_display_types' setting.

Return value

array The array of options.

File

src/Plugin/Field/FieldType/ViewfieldItem.php, line 206

Class

ViewfieldItem
Plugin implementation of the 'viewfield' field type.

Namespace

Drupal\viewfield\Plugin\Field\FieldType

Code

public function getDisplayOptions($entity_id, $filter = TRUE) {
  $display_options = [];
  $views = Views::getEnabledViews();
  if (isset($views[$entity_id])) {
    $allowed_display_types = $filter ? array_filter($this
      ->getSetting('allowed_display_types')) : [];
    foreach ($views[$entity_id]
      ->get('display') as $key => $display) {
      if (empty($allowed_display_types) || isset($allowed_display_types[$display['display_plugin']])) {
        $display_options[$key] = FieldFilteredMarkup::create($display['display_title']);
      }
    }
    natcasesort($display_options);
  }
  return $display_options;
}