protected function ViewsReferenceTrait::getViewDisplays in Views Reference Field 8.2
Get displays for a particular view.
Parameters
string $view_id: The view ID.
Return value
array An array containing displays for the view.
1 call to ViewsReferenceTrait::getViewDisplays()
- ViewsReferenceTrait::fieldElement in src/
Plugin/ Field/ FieldWidget/ ViewsReferenceTrait.php - Build a field element for a viewsreference field.
File
- src/
Plugin/ Field/ FieldWidget/ ViewsReferenceTrait.php, line 317
Class
- ViewsReferenceTrait
- Trait for shared code in Viewsreference Field Widgets.
Namespace
Drupal\viewsreference\Plugin\Field\FieldWidgetCode
protected function getViewDisplays($view_id) {
$options = [];
$view_plugins = array_diff($this
->getFieldSetting('plugin_types'), [
'0',
]);
/** @var \Drupal\views\Entity\View $view */
if ($view = \Drupal::service('entity_type.manager')
->getStorage('view')
->load($view_id)) {
if ($displays = $view
->get('display')) {
usort($displays, function ($a, $b) {
return $a['position'] <=> $b['position'];
});
foreach ($displays as $display) {
if (in_array($display['display_plugin'], $view_plugins, TRUE)) {
$options[$display['id']] = $display['display_title'];
}
}
}
}
return $options;
}