views_get_current_view returns null I have placed the following function in my .module file to get the information of current view. But it returns null

public function buildForm(array $form, FormStateInterface $form_state) {
    $record = array();
    $view = views_get_current_view();
}


I have added use Drupal\views\Views; in the top.

What could be the reason to return null. Am i missing anything?
views_get_current_view() seems to be from the early days of procedural code and I don't know how this can be used in connection with form building in D8.

You can get the current view from the current route, if this is what you are looking for:

use Drupal\views\Entity\View;

  $view_id = \Drupal::routeMatch()-&gt;getParameter('view_id');
  if ($view_id) {
    $view = View::load($view_id);
  }