ContentEntityForm buildForm method parent out of memory I have the following issue with my form class that extends the ContentEntityForm class. 

When calling the parent buildForm which is needed my system runs out of memory. 

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildForm($form, $form_state);
    // Here is already runs of memory. $form is never initiated.

    /* @var $entity \Drupal\sg_configuration_rule\Entity\ConfigurationRule */
    $entity = $this-&gt;entity;

    $form_state-&gt;set('old_cron_value', $entity-&gt;get('cron_settings')-&gt;first()-&gt;value);

    $type = FALSE;

    if (!$entity-&gt;isNew()) {
      $type = $entity-&gt;getPluginInstance()-&gt;getPluginId();
    }

    if ($entity-&gt;isNew()) {
      $type = \Drupal::request()-&gt;query-&gt;get('type');
      if (!$type) {
        return new RedirectResponse(Url::fromRoute('configuration_rule.add_form_step1')-&gt;toString());
      }
    }

    if ($type) {
      try {
        /** @var \Drupal\sg_base_api\Plugin\BaseApiPluginInterface $enabled_api */
        $enabled_api = $this-&gt;baseApiPluginManager-&gt;createInstance($type);
      }
      catch (PluginException $exception) {
        LoggerService::error($exception-&gt;getMessage());
        return new RedirectResponse(Url::fromRoute('configuration_rule.add_form_step1')-&gt;toString());
      }

      $enabled_api-&gt;configRuleForm($form, $entity);

      $form['plugin_type']['widget'][0]['value']['#value'] = $type;
      $form['plugin_type']['widget'][0]['value']['#access'] = FALSE;
      $form['plugin_type']['widget'][0]['value']['#disabled'] = TRUE;
      $form['server_node']['widget']['#options'] = $this-&gt;getServerNodesByType($enabled_api-&gt;entityType());
    }

    $form['user_id']['#access'] = FALSE;

    return $form;
  }


When i check the parent function i noticed that the line: 

$form = $this->form($form, $form_state); is causing this in the class EntityForm(Core method).

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    // During the initial form build, add this form object to the form state and
    // allow for initial preparation before form building and processing.
    if (!$form_state-&gt;has('entity_form_initialized')) {
      $this-&gt;init($form_state);
    }

    // Ensure that edit forms have the correct cacheability metadata so they can
    // be cached.
    if (!$this-&gt;entity-&gt;isNew()) {
      \Drupal::service('renderer')-&gt;addCacheableDependency($form, $this-&gt;entity);
    }

    // Retrieve the form array using the possibly updated entity in form state.
    // This is causing my memory timeout.
    $form = $this-&gt;form($form, $form_state);

    // Retrieve and add the form actions array.
    $actions = $this-&gt;actionsElement($form, $form_state);
    if (!empty($actions)) {
      $form['actions'] = $actions;
    }

    return $form;
  }


If i comment that line out it is working fine but this is needed to save my values in config. Also this is core and should work. 

Anyone else have this problem and knows the solutions to this? 



Thanks.
Are you sure this is a coding error? Are you loading any large quantities of content in the form by any chance? Loading a lot of nodes in a select field, for instance, can generate memory overflows.