I'm really new to drupal 8. I want to add a link in register form.
I have been tried all the ways about hook_form_alter() and flush changes. It still doesn't work.
This is my module code.
<?php
/**
* Implements hook_theme().
*/
function hook_register_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
echo "alter the form"; exit;
}
Function hook_form_alter is used to perform alterations to the forms rendered. You should take care of the naming of hooks, since Drupal loads the hooks according to the name suggestions.
In your above code, you haven't provided the module name in function name. That is, the word
hookshould be replaced with yourmodule name.For Example, If your module name is
foo. Then the above hook should be written as:Also, in your code since you provided
registerin the code, I assume it is the ID of the form you are targeting to. For that, you should changed the code to:You could refer the difference between from the below official Drupal links: hook_form_alter hook_form_FORM_ID_alter