Problem/Motivation

Webform will be a default module for Drupal CMS. Our goal for Lupus Decoupled is to fully support all features of Drupal CMS until its release in January.

Proposed resolution

Needs concept.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

useernamee created an issue. See original summary.

useernamee’s picture

Status: Active » Needs review
fago’s picture

Title: Webform support » Add webform support
Status: Needs review » Needs work

thanks! please see my comments!

useernamee’s picture

Status: Needs work » Needs review

I've implemented most of the PR comments.

I think the one regarding the documentation was already covered by ld_form README file.

I added additional type attribute to custom element because that data was lost after I utilized more ld_form code and simplified the output.

I was surprised by isApiResponse method code quadruplication. This should probably be caught before.

New output looks like:

  "content": {
    "element": "drupal-form-webform-submission-to-spar-add-form",
    "formId": "webform_submission_to_spar_add_form",
    "attributes": {
      "class": [
        "webform-submission-form",
        "webform-submission-add-form",
        "webform-submission-to-spar-form",
        "webform-submission-to-spar-add-form",
        "webform-submission-to-spar-add-form",
        "webform-submission-to-spar-form",
        "js-webform-details-toggle",
        "webform-details-toggle"
      ],
      "dataDrupalSelector": "webform-submission-to-spar-add-form"
    },
    "method": "post",
    "type": "webform",
    "title": "to spar",
    "content": "<div class=\"form-type-checkbox js-form-item form-item js-form-type-checkbox form-type--checkbox form-type--boolean js-form-item-going form-item--going\">\n            <input data-drupal-selector=\"edit-going\" type=\"checkbox\" id=\"edit-going\" name=\"going\" value=\"1\" class=\"form-checkbox form-boolean form-boolean--type-checkbox\"/>\n\n              <label for=\"edit-going\" class=\"form-item__label option\">going</label>\n            </div>\n<div class=\"form-type-textfield js-form-item form-item js-form-type-textfield form-type--textfield js-form-item-how-much-to-spend form-item--how-much-to-spend\">\n            <label for=\"edit-how-much-to-spend\" class=\"form-item__label\">how much to spend</label>\n              <input data-drupal-selector=\"edit-how-much-to-spend\" type=\"text\" id=\"edit-how-much-to-spend\" name=\"how_much_to_spend\" value=\"\" size=\"60\" maxlength=\"255\" class=\"form-text form-element form-element--type-text form-element--api-textfield\"/>\n          </div>\n<input data-drupal-selector=\"form-jddxnw6y8r0c23sukubghfixbb61zfxvanzlwlgu5ei\" type=\"hidden\" name=\"form_build_id\" value=\"form-Jddxnw6Y8r0C23sUKubGHFixBb61zFxvANZLWlGU5eI\"/><input data-drupal-selector=\"edit-webform-submission-to-spar-add-form-form-token\" type=\"hidden\" name=\"form_token\" value=\"h7FrU478ituV4WXR32dKPgTnxogEMsZMbxglbvt_Ewo\"/><input data-drupal-selector=\"edit-webform-submission-to-spar-add-form\" type=\"hidden\" name=\"form_id\" value=\"webform_submission_to_spar_add_form\"/><div data-drupal-selector=\"edit-actions\" class=\"form-actions js-form-wrapper form-wrapper\" id=\"edit-actions\"><input class=\"webform-button--submit button button--primary js-form-submit form-submit\" data-drupal-selector=\"edit-submit\" type=\"submit\" id=\"edit-submit\" name=\"op\" value=\"Submit\"/>\n</div>\n\n"
  },
arthur_lorenz’s picture

Status: Needs review » Needs work

By default webform uses the confirmation type "page". However confirmation pages are not supported, resulting in a redirect to Drupal's frontend. I see multiple possible solutions:

  • Support confirmation pages
  • Disallow confirmation types except for inline confirmation
  • Set inline confirmation as a default and add a warning if changed to any non-supported type
fago’s picture

If we could easily support confirmation pages, that would be best. Else I guess we should at least have a working default.

Generally, we are not warning users of not supported stuff, that would be lots of work, would it? Or should we make an exception for that crucial setting and grey-out/disable not supported options? This means, enabling the module takes over all webforms and considers them decoupled. Maybe it would be nice to allow configuring that, but again, complexity, so I think it's ok to keep it simple and make all webforms deocupled once turned on.

useernamee’s picture

Assigned: Unassigned » useernamee
useernamee’s picture

Enabling confirmation was not problematic but there's a strange access check in webform that allowed me to access confirmation page only when logged in as admin:

/webform/src/WebformEntityAccessControlHandler::checkAccess

    // Check 'view' operation use 'submission_create' when viewing rendered
    // HTML webform or use access 'configuration' when requesting a
    // webform's configuration via REST or JSON API.
    // @see https://www.drupal.org/project/webform/issues/2956771
    if ($operation === 'view') {
      // Check is current request if for HTML.
      $is_html = ($this->requestStack->getCurrentRequest()->getRequestFormat() === 'html');
      // Make sure JSON API 1.x requests format which is 'html' is
      // detected properly.
      // @see https://www.drupal.org/project/jsonapi/issues/2877584
      $is_jsonapi = (strpos($this->requestStack->getCurrentRequest()->getPathInfo(), '/jsonapi/') === 0) ? TRUE : FALSE;
      if ($is_html && !$is_jsonapi) {
        $access_result = $this->accessRulesManager->checkWebformAccess('create', $account, $entity);
      }
      else {
        if ($account->hasPermission('access any webform configuration') || ($account->hasPermission('access own webform configuration') && $is_owner)) {
          $access_result = WebformAccessResult::allowed($entity, TRUE);
        }
        else {
          $access_result = $this->accessRulesManager->checkWebformAccess('configuration', $account, $entity); // <- this denies access to confirmation page !!!
        }
      }
      if ($access_result instanceof AccessResultReasonInterface) {
        $access_result->setReason('Access to webform configuration is required.');
      }
      return $access_result->addCacheContexts(['url.path', 'request_format']);
    }
useernamee’s picture

Ok, I figured it out and added a section to the README.md file.

useernamee’s picture

Assigned: useernamee » Unassigned
Status: Needs work » Needs review
arthur_lorenz’s picture

Status: Needs review » Reviewed & tested by the community

Thx, comments were adressed. I tested by creating a webform including 2 pages and confirmation page -> works like documented.

  • useernamee committed 498f1c9a on 1.x
    Issue #3487279 by useernamee, fago, arthur_lorenz: Add webform support
    
useernamee’s picture

Status: Reviewed & tested by the community » Fixed

Merged.
Bug hunting season starts now.

Status: Fixed » Closed (fixed)

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