mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Dynamically copy all exposed filters from farm_asset View to farm_asset_geojson Views.
This allows the map on /assets/% to be filtered with the same exposed filters as the farm_asset View itself.
This commit is contained in:
parent
33c47849b8
commit
4f8583593a
|
@ -5,6 +5,7 @@
|
|||
* The farmOS UI Map module.
|
||||
*/
|
||||
|
||||
use Drupal\views\Entity\View;
|
||||
use Drupal\views\ViewExecutable;
|
||||
|
||||
/**
|
||||
|
@ -18,6 +19,31 @@ function farm_ui_map_farm_dashboard_panes() {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_pre_view().
|
||||
*/
|
||||
function farm_ui_map_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
|
||||
|
||||
// Alter the farm_asset_geojson View's full and centroid displays to add all
|
||||
// exposed filters that are present in the farm_asset View.
|
||||
if ($view->id() == 'farm_asset_geojson' && in_array($display_id, ['full', 'centroid'])) {
|
||||
|
||||
// Load the farm_asset View. Bail if unavailable.
|
||||
$farm_asset_view = View::load('farm_asset');
|
||||
if (empty($farm_asset_view)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Copy all exposed filters from the default display.
|
||||
$display = $farm_asset_view->getDisplay('default');
|
||||
if (!empty($display['display_options']['filters'])) {
|
||||
foreach ($display['display_options']['filters'] as $field => $filter) {
|
||||
$view->addHandler($display_id, 'filter', $filter['table'], $field, $filter, $filter['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_pre_render().
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue