I'm trying to port the OpenID module from Drupal 7 to Drupal 8.
I have a form OpenIdLoginForm.php with the following code.
<?php
...
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.
<?php
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.
modules/
openid/
README.md
openid.module
...
src/
Form/
OpenIdLoginForm.php
...
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.