The problem is all in the title. So here is my code (i cut some part to make it more visible) :
Constructor :
public function __construct() { $user = DrupaluserEntityUser::load(Drupal::currentUser()->id()); $this->sub_forms['user'] = Drupal::service('entity.form_builder')->getForm($user); }
buildForm :
public function buildForm(array $form, FormStateInterface $form_state) { $sub_forms_keys = array_keys($this->sub_forms); // INC ALL SUBFORM INTO THE MAIN FORM foreach ($this->sub_forms as $key => $sub_form) { // REMOVE THE PROCESS CALLBACK if (!empty($sub_form['#process'])) { unset($sub_form['#process']); } // ALTER THE SUBFORM if ($key == $sub_forms_keys[0]) { // user Alter foreach ($sub_form as $field_key => $sub_form_field) { // Pour tous les champs if (substr($field_key, 0, 10) != 'field_user') { // Si ce n'est pas un champ personnalisé friterie unset($sub_form[$field_key]); // Cacher le champ } else if (array_key_exists('widget', $sub_form[$field_key])) // Si c'est un champ friterie et qu'il dispose d'un widget $sub_form_field_widget = $sub_form[$field_key]['widget'][0]; $sub_form_field_widget['#states'] = array( 'visible' => array( ':input[#edit-proprietaire-0]' => array('checked' => true), ) ); dsm($sub_form_field_widget); } } } // ADD THE SUBFORM INTO THE MAIN FORM $form[$key] = [ '#type' => 'container', 'form' => $sub_form ]; } return $form; }
Here is a pastern link of a dsm() of a field to show you the structure and that the #states is include : http://pastebin.com/1a8AqVzm
Then here is the HTML code of the entity i want to focus (it’s a radio button) :
<input class="clear-panel-field panel-field-inline container-inline form-radio" data-drupal-selector="edit-proprietaire-0" type="radio" id="edit-proprietaire-0" name="proprietaire" value="0">