protected function DraggableViewsSort::getViewSortDataOptions in DraggableViews 2.0.x
Grab available draggable views.
1 call to DraggableViewsSort::getViewSortDataOptions()
- DraggableViewsSort::buildOptionsForm in src/
Plugin/ views/ sort/ DraggableViewsSort.php - Basic options for all sort criteria.
File
- src/
Plugin/ views/ sort/ DraggableViewsSort.php, line 133
Class
- DraggableViewsSort
- Basic sort handler for Draggableviews Weight.
Namespace
Drupal\draggableviews\Plugin\views\sortCode
protected function getViewSortDataOptions() {
$view_data = [];
$query = \Drupal::entityQuery('view');
$entity_ids = $query
->execute();
foreach ($entity_ids as $view_id) {
$v = View::load($view_id);
$default_display = NULL;
foreach ($v
->get('display') as $display_id => $display) {
if ($display_id == "default") {
$default_display = $display;
}
else {
// Use default if fields are not overwritten.
$fields = !empty($display['display_options']['fields']) ? $display['display_options']['fields'] : $default_display['display_options']['fields'];
// Need to check that "fields" is an array, view may be configured to
// render rows otherwise.
if (is_array($fields) && in_array("draggableviews", array_keys($fields))) {
if (!isset($view_data[$view_id])) {
$view_data[$view_id] = [
'id' => $view_id,
'label' => $v
->label(),
'displays' => [],
];
}
$view_data[$view_id]['displays'][$display_id] = [
'id' => $display_id,
'label' => $display['display_title'],
];
}
}
}
}
$view_select = [
'this' => "This View/Display",
];
foreach ($view_data as $view_id => $v_data) {
$view_key = $v_data['label'] . " (" . $view_id . ")";
$view_select[$view_key] = [];
foreach ($v_data['displays'] as $display) {
$display_key = $view_id . ":" . $display['id'];
$view_select[$view_key][$display_key] = $display['label'];
}
}
return $view_select;
}