Which files do I need to edit to alter webform #states with hook_form_alter? I need to create #states conditions between either the fields in any one element in a webform or across other elements in the same form. I'd hoped I could do it via the WF yaml editor but it seems I couldn't [1].  As per @jrockowitz 's comment on the attached link #1, I 


  might be able to use a form alter hook to add the needed #states


I am not a developer but it seems with drupal 8+ I do need to learn to start to be one and that's on my list for sure. I'd love to be able to contribute something to Drupal and especially webform but I find the learning process intimidating especially with the lack of "beginner-type" tutorials at least when it comes to creating custom modules with more than "hello world!". 

For now, I need to know the steps I need to follow @jrockowitz 's advice and use hook_form_alter to serve my goal. My understanding is that could be done either on a theme level or custom module level (please correct me if wrong) and since I'm more comfortable with the theme way and I feel it's simpler for someone like me, I like to know (at least):


which files ( other than MYTHEME.theme) I need to edit or/and create to start with and
what info do I need to look for and study so I can do the job and begin my learning journey. 
I learn best by example and so any extra clear a-b-c type tips to get me started is greatly valued if any. 


If the custom module way is more advisable or the only way:


What is the minimal skeleton of a custom module that I need to have for the purpose.
What do I need to study to learn how to create such a module.


(I'm not sure if the last question should be a separate question so please forgive my newbie status here but I promise I've done my best)

Thanks so much everyone

A sample of what I want to achieve:

some_question:
  '#type': tableselect
  '#title': 'some question'
  '#options':
    q1: 'q1 (hide if q2 is checked)'
    q2: 'q2 (hide if q1 is checked)'
    q3: q3
    q4: q4
    q5: q5
    q6: q6
    q7: q7


Related links:

[1] Why isn&#39;t my custom Form API #states applied in my webform yaml editor working?

[2] https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21form.api.php/function/hook_form_alter/8.7.x

[3] https://www.jrockowitz.com/blog/add-ons
Ok, if you need to rely on custom dev, you can indeed use hook_form_alter().

It would work if you set it in your mytheme.theme file but for unrelated theme issues I prefer to rely on custom modules.
To create your module:


Create a mymodule.info.yml file in the folder /modules/custom/mymodule of your Drupal website. See this page for providing your file with the minimal content to have your module detected by Drupal.
With only this file you should be able to enable your module
Create a mymodule.module file at the same level as your .info.yml file
In your .module file (or mytheme.theme if you chose not to create a module), add the following:



function mymodule_form_alter(&$form, &$form_state, $form_id) {
  // Target your form
  if($form_id == "your_form_id") {
    // Use Devel Kint module to display the architecture of your form and make it easier for you to find the elements you wish to alter
    kint($form); 
    // Now you can access the elements of your form and edit the desired ones

    // Hide checkbox "my_checkbox_name" if checkbox "my_other_checkbox" is checked
    $form['my_checkbox_name']['#states'] = array(
      'invisible' => array(
        ':input[name="my_other_checkbox"]' => array('checked' => TRUE),
      )
    );
    // Make field "some_input_text" required if input field "some_other_input" is filled with value 'hello'
    $form['some_input_text']['#states'] = array(
      'required' => array(
        ':input[name="some_other_input"]' => array('value' => 'hello'),
      )
    );
  }
}

I recommend you to have a look at this page for the list of available #states and some examples as well.

Happy coding!