I'm very new to Drupal development and I am completely stuck(.

I have a custom content form, where I need to hide some fields in Inline Entity Form. I am trying to write my own custom module to achieve this, I am doing the following: 1. I create module folder, where I put info.yml file 2. I create Controller file, where I add custom class and this code inside this class:

public function MY_MODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) {if ($form_id == 'MY_FORM') {...};
  1. The next thing I am completely stuck at is do I need a routing file to make this work? I can't find any info about this so I'd really appreciate some help! And if I need routing, what should I write there?

Thank you very much! I really didn't need routing!

Well, finally I found the solution to my problem - I created the module with 2 files only - mymodule.info.yml and mymodule.module. In .module file I only added these lines of code and everything worked! (Almost)

function mymodule_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) { 
if ($entity_form['#entity_type'] == 'node' && $entity_form['#bundle'] == 'my_custom_content_type_machine_name') { 
|improve this answer|||||
  • This is great news that you went this far. Providing this as answer will mostly prevent people from posting any answer especially since your new question is in AN ANSWER. I think you should either consider editing the question with your new findings or create a new. – GiorgosK Apr 5 '19 at 10:30
  • Thank you for your suggestion! I will create new question! – JuliaK Apr 5 '19 at 10:31

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.