I have a module that is building a form. I want to theme the form using twig within my module so it does not interfere with my theme/custom twigs.
My buildForm function is:
public function buildForm(array $form, FormStateInterface $form_state) { $form['name'] = array( '#type' => 'textfield', '#title' => $this->t('Name'), '#title_display' => 'invisible', '#required' => TRUE, ); $form['#theme'] = 'custom_form'; return $form; }
I have set the theme for the form as custom_form
and it works fine using this in my .module file:
function custom_module_theme($existing, $type, $theme, $path) { return array( 'custom_form' => array( 'render element' => 'form', ), 'input' => array( 'template' => 'input', 'render element' => 'element', ), ); }
However the input fields are still being rendered using input.html.twig
file in my /theme/custom theme folder.
I have created copied the twig template file using the same name and placed it in my custom_module folder however Drupal is still using my theme input.html.twig file.
How do I override this twig and use the input.html.twig file in my custom_module templates folder?
Thanks