2

I'm using the material_admin theme, which has a hook_form_alter() implementation.

I see that my module's hook_form_alter() is executed before the theme hook. Both hooks are editing the same form property, so the change done in my code is always overridden.

In my hook_module_implements_alter() implementation I see only the modules that implement hook_form_alter(). The theme's implementation is not there.

How can I control its execution?

1
  • If your module is executes last it should not be overridden.
    – user72672
    Sep 3, 2019 at 8:46

1 Answer 1

5

I think you cannot have a module hook executed the same hook implemented by a theme. If we look at the hook invoking code, we see that the theme hooks are invoked separately and after the module hooks.

The best bet would be to remove it from the theme and put it in a module, or trying with #after_build.

FormBuilder.php contains the following code.

$this->moduleHandler->alter($hooks, $form, $form_state, $form_id);
$this->themeManager->alter($hooks, $form, $form_state, $form_id);
3
  • Thanks that is helpful, I cannot remove it since material_admin is a contributed theme, and the project is maintained.Only with a patch which I'd like to avoid..
    – Pan Chrono
    Sep 3, 2019 at 8:53
  • 1
    Maybe try #after_build form form API instead Sep 3, 2019 at 8:54
  • 2
    Or you can create subtheme based on material_admin and implement your form_alter hook it will be executed after the material_admin form_alter hook.
    – berramou
    Sep 3, 2019 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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