I'm trying to port the OpenID module from Drupal 7 to Drupal 8.

I have a form OpenIdLoginForm.php with the following code.

namespace Drupal\openid\Form;
use Drupal\user\Form\UserLoginForm;
use Drupal\Core\Form\FormStateInterface
use Drupal\Core\Url;
use Drupal\user\UserStorageInterface
class OpenIdLoginForm extends UserLoginForm {
... // getFormId, buildForm methods work nicely

  public function validateForm(array &$form, FormStateInterface $form_state) {
    ... // some validations
    openid_begin($claimed_id, $return_to, $form_state);

... // submitForm method

openid_begin is defined in openid.module.


use Drupal\Core\Routing\RouteMatchInterface;

... // openid_help, working nicely

function openid_begin($claimed_id, $return_to = '', $form_state = null) { 
  // some stuff

The folder structure is the following.


Whenever I submit the form, and validateForm() is called, I get an error:

PHP Fatal error: Call to undefined function Drupal\openid\Form\openid_begin() in /modules/openid/src/Form/OpenIdLoginForm.php

What am I doing wrong? How would I invoke a module function from a form belonging to the same module?

Fun fact: invoking the function user_login_finalize() from submitForm() in OpenIdLoginForm.php works and I don't know why.

1 Answer 1


I was looking for a solution for hours. Right after posting the question, i found one:



seems to do the trick.

Still, I wonder why I can call user_login_finalize directly.

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.