1

I am trying to update a old custom module written for Drupal 7 for Drupal 8. I have used a lot of view functions like views_include() and views_get_view(). Are they all dropped in Drupal 8?

function validate_email($email) {   
    //pass the email to the filter
    views_include('view');  
    $name = 'send_otp';
    $display = 'page_1';
    $alter = array('exposed' =>array('field_email_value' => $email));
    $view = views_get_view($name);
    $view->init_display($display);
    $view->preview=TRUE;
    $view->is_cacheable = FALSE;    
    if(isset($alter['exposed'])) {
        foreach($alter['exposed'] as $key => $valor) {
            $view->exposed_input[$key] = $valor;
        }
    }
    $view->pre_execute();
    $output = $view->display_handler->preview();
    $view->post_execute();
    //if the result is empty
    if(empty($view->result)) {
        //return 0
        return 0;
    }
    else {
        //return node id
        return $view->result[0]->nid;
    }   
}

Fatal error: Call to undefined function views_include() in /var/www/html/mdc-conference-backend/sites/all/modules/custom/rest/sendotp.php on line 43

2

views_get_view became Views::getView, and several others are now static methods on the Views class in the views module.

I don't think views_include is necessary anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.