FormState getValue on checkbox elements in hierarchical / tabular form structures broken? I can't seem to retrieve correct posted checkbox form element values using an array-style key in a call to the FormState::getValue method. If I flatten the elements into a non-nested structure, the getValue method works. But, I need to lay out the components using a table form element. The values that I get back (empty or "0") do not match the actual user-checked box states by the time they post in submitForm. I've also tried a zillion variants of reversed #parent array hints, #array_parent hints, #return_value, etc. It feels like there may be a bug in the getValues method in how it handles array-style keys? Or, am I doing something dumb?

class DataFsFolderSharingForm extends ContentEntityForm {

  // … stripped down to the bare essentials...

  public function buildForm(array $form, FormStateInterface $form_state, DataFsFolderInterface $folder = NULL) {
    // Documentation for for element attributes (eg: '#parents’, '#array_parents’, '#return_value’, etc):
    //   @see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21Element%21FormElement.php/class/FormElement/8.2.x

    $form = [];
    $form['#tree'] = TRUE;

    // Show the current access settings as a table.
    //   @see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21Element%21Table.php/class/Table/8.2.x
    $form['access'] = [
      '#type'    =&gt; 'table',
      '#caption' =&gt; $this-&gt;t('Sharing Access'),
      '#header'  =&gt; [
        $this-&gt;t('User Email'),
        $this-&gt;t('View'),
        $this-&gt;t('Edit'),
        $this-&gt;t('Operation'),
      ],
      // '#array_parents' =&gt; array( 'access' ),
      // '#name' =&gt; 'access',
    ];

    // Non-nested element structure doesn’t break getValue method.
    $form['flat'] = [
      '#type' =&gt; 'checkbox',
      // '#name' =&gt; 'check-2',
      // '#return_value' =&gt; 1,
      // '#default_value' =&gt; 1,
      // '#array_parents' =&gt; array( 'flat' ),
    ];

    // Nested element structure breaks getValue method.
    //   @see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21Element%21Table.php/class/Table/8.2.x
    $form['access'][0]['view'] = [
      '#type'          =&gt; 'checkbox',
      // '#name' =&gt; 'check-1',
      // '#return_value' =&gt; 1,
      '#default_value' =&gt; 1,
      // '#array_parents' =&gt; array( 'access', 0, 'view' ),
    ];

    // ...more table elements added, who's rows are indexed by the middle integer array value...

    return $form;
  }

  public function submitForm(array &amp;$form, FormStateInterface $form_state) {
    // The non-nested getValue returns the correct checkbox state (checked or unchecked).
    $checked = $form_state-&gt;getValue('flat');

    // The nested getValue returns the incorrect checkbox state (checked or unchecked).
    //  @see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21FormState.php/function/FormState%3A%3AgetValue/8.2.x
    $checked = $form_state-&gt;getValue(['access', 0, 'view']);

    // Also tried ['access', '0', 'view’ ]
    // Also tried ['view’, 0, 'access’ ]
    // Also tried ['view’, '0', 'access’ ]
    // Also tried setting '#parents’ form element attribute.
    // Also tried not setting '#array_parents’ form element attribute.
    // Also tried reversed version of '#parents’ form element attribute.
    // Also tried reversed version of '#array_parents’ form element attribute.
    // Also tried setting '#return_value’ form element attribute (using 1, 0, TRUE, FALSE, '0’, '1’, etc).
    // Also tried setting '#default_value’ form element attribute (using 1, 0, TRUE, FALSE, '0’, '1’, etc).
  }
}
Anyone still having this problem please allow collections of form elements using #tree set to TRUE. Its applied to the &quot;parent&quot; element, as the #tree property cascades to sub-elements. Use where you previously used in form calls. See D7 #tree and #parents on drupal.org.
Solution
Example for above case, change $form['#tree'] = TRUE; to $form['access']['#tree'] = TRUE; then the value will be obtained using $checked = $form_state-&gt;getValue(['access', 0, 'view']);.