entity_form removes uid So i have defined a block

case 'foo_post':
    global $user;
    $values = array(
        'type' =&gt; 'foo',
        'uid' =&gt; $user-&gt;uid,
        'status' =&gt; 1,
        'comment' =&gt; 0,
        'promote' =&gt; 0
    );
    $entity = entity_create('node', $values);

    $ewrapper = entity_metadata_wrapper('node', $entity);
    $ewrapper-&gt;og_group_ref-&gt;set(menu_get_object()-&gt;nid);

    $block['subject'] = t('Create a new foo');
    $block['content'] = entity_form('node', $entity, 'add');
    $block['content']['#attributes']['class'][] = drupal_html_class('panel-body');
    $block['content']['title']['#access'] = FALSE;
    $block['content']['form_title'] = ['#markup' =&gt; sprintf('&lt;h4&gt;%s&lt;/h4&gt;', $block['subject']), '#weight' =&gt; -1];
    $block['content']['form_advanced'] = [
        '#collapsible' =&gt; TRUE,
        '#collapsed' =&gt; TRUE,
        '#type' =&gt; 'fieldset',
        '#title' =&gt; t('Advanced settings'),
        'additional_settings' =&gt; $block['content']['additional_settings'],
        'og_group_ref' =&gt; $block['content']['og_group_ref']
    ];
    unset($block['content']['og_group_ref']);
    unset($block['content']['additional_settings']);
    break;


Most of the things work already, except the form wouldn't take the user ID of the user submitting the form. What did I do wrong here?
The $user variable may not be set in this context - it is not automatically available as a local variable. 

Try adding global $user; before the code.