I’ve added a custom field to a view and want to display results as a grid grouped by this field. How do I set that “Grouping field Nr.1” option in my code? I tried the hook_views_pre_build()
using the $view->addHandler
but m not able to make it work. I guess the issue lies in the $option
array and the $type
parameter for addHandler
method. Here is my code.
function utility_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
if ($view->id() == 'frontpage' && $display_id == 'page_1') {
$options = array(
'style' => array(
'options' => array(
'grouping' => array(
'field_category',
),
),
),
);
$view->addHandler("page_1", "grouping", "node__field_category", "field_category", $options);
}
}
Update
When I use $view->addHandler("page_1", "field", "node__field_category", "field_category", $options);
I get the a catgeory field added to each of the view items.
Can anyone help me on this?
Sponsored by SupremePR