Drupal 8 views ui : filter on custom field -
i m pretty new d8 , m trying following thing :
i have content type : movie. in content type have custom field api_id wich integer.
when on movie page want display under content block movies same api_id.
i have managed create block same movies same author can't figure out how to filter on api_id (i have played contextual filters ...)
any ideas ? thx
ok , manage want hook_views_query_alter() :
function my_module_views_query_alter(\drupal\views\viewexecutable $view, \drupal\views\plugin\views\query\querypluginbase $query) { if($view->id() == 'my_view' && $view->current_display == 'my_block'){ $movie= node::load($view->args[0]); if(is_object($movie)) { foreach ($query->where &$condition_group) { foreach ($condition_group['conditions'] &$condition) { if ($condition['field'] == 'node__field_id_movie.field_id_movie_value') { $condition = array( 'field' => 'node__field_id_movie.field_id_movie_value', 'value' => $movie->get('field_id_movie')->value, 'operator' => '=', ); } } } } } }
to have first create view simple filter on field want override filter.
Comments
Post a Comment