Problem/Motivation

Elements endpoint webform_rest/{webform_id}/elements?_format=json takes forever to load on a very complex webforms.

Proposed resolution

Instead of returning renderable array maybe return simpler JSON ?

The following code load much faster and provides everything needed to build the form on front end.

<?php  public function get($webform_id) {
    if (empty($webform_id)) {
      throw new HttpException(t("Webform ID wasn't provided"));
    }

    // Load the webform.
    $webform = Webform::load($webform_id);

    // Basic check to see if something's returned.
    if ($webform) {
      // Return only the form elements.
      return new ModifiedResourceResponse($webform->getElementsInitialized());
    }

    throw new HttpException(t("Can't load webform."));

  }

Also it is probably a good idea to cache response and use Cache tags to invalidate cache and provide the most recent data.

Comments

minnur created an issue. See original summary.

minnur’s picture

Issue summary: View changes
imclean’s picture

Sounds good. I did look at getElementsInitialized() but can't remember why I discounted it. Is the output the same as the render array?

Caching would also be useful.

minnur’s picture

Here is what I created for the project that I am working on https://github.com/minnur/webform_restapi

imclean’s picture

Thanks. I don't have time to test much in the next few days and was wondering if I changed the code as you suggested would the output also be changed?

Does adding cache metadata work OK with ResourceResponse when an email handler is set for the webform? Is that part of the webform object?

imclean’s picture

I do support the idea of caching and using Webform's built in methods for obtaining form elements, such as getElementsInitialized(). This would require an additional endpoint as it's changing the output.

  • imclean committed 829f2e3 on 8.x-2.x authored by minnur
    Issue #2952433 by minnur: Complex and very long forms won't load
    
imclean’s picture

Thanks. I've added getElementsInitialized() as a new endpoint /webform_rest/{webform_id}fields.

Caching will require more testing I think.

imclean’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.