hook_form_FORM_ID_alter in theme file to toggle field visibility I have a boolean check box that I want to control the visibility of an entity-reference field below it.  By default, this check box is unchecked, which means the entity-reference field should not be shown. 

I've tried a handful of things in my .theme file, but I can't seem to solve the problem.  

use Drupal\Core\Form\FormStateInterface;

function mytheme_form_node_news_form_alter(&amp;$form, FormStateInterface 
  &amp;$form_state, $form_id) {
    $form['field_news_top_story_image']['#states'] = [ 
    'visible' =&gt; [ 
        ':input[name="field_news_topstory"]' =&gt; ['checked' =&gt; TRUE] 
    ]
];


}

node_news_form (and eventually node_news_edit_form once I figure this out) appears to be the form I want to affect.  field_news_topstory is my checkbox and field_news_top_story_image is the entity-reference field I want to hide* until field_news_topstory is checked.  *I've set this field to disabled in Manage Form Display.

Am I close?  :)

EDIT: Had my code backwards, but still not working.
After a lot of banging on this, I found the right combo.  We don't have a custom admin theme, so I ended up moving this code in to a custom module.

The important part I was missing was [value] in ':input[name="field_news_topstory[value]"]' => ['checked' => TRUE]  

use Drupal\Core\Form\FormStateInterface;

function mymodule_form_node_news_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {
    $form['field_news_top_story_image']['#states'] = [
       'visible' =&gt; [
         ':input[name="field_news_topstory[value]"]' =&gt; ['checked' =&gt; TRUE]
       ]
   ];
}