PHP 8.1 TypeError: Drupal\webform\WebformRequest::getUrl()

Created on 25 September 2022, almost 3 years ago
Updated 6 April 2023, over 2 years ago

Problem/Motivation

TypeError: Drupal\webform\WebformRequest::getUrl(): Argument #1 ($webform_entity) must be of type Drupal\Core\Entity\EntityInterface, null given, called in web/modules/contrib/webform/src/WebformMessageManager.php on line 247 in Drupal\webform\WebformRequest->getUrl() (line 229 of web/modules/contrib/webform/src/WebformRequest.php) #0 web/modules/contrib/webform/src/WebformMessageManager.php(247): Drupal\webform\WebformRequest->getUrl()

Proposed resolution

Check that webform_entity isn't null before using getUrl().

πŸ› Bug report
Status

Closed: cannot reproduce

Version

6.1

Component

Code

Created by

πŸ‡©πŸ‡°Denmark pmchristensen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom siliconandincense

    I know this has been set as closed, but I am also getting this error by using the following steps:

    1) I have a regular content type page that is already published
    2) I set this page as draft and save it
    3) I add a webform via a paragragraph, which has a webform reference field on it
    4) I save the page
    5) I view the page and get the same error as above

    I know this is a very personalised set of steps, but I'm hoping this may shed a little more light on the issue.

    Can confirm #2 works, but as you say in #3 we get the submission message.

    Apologese if this has been sorted in a subsequent ticket.

  • πŸ‡·πŸ‡΄Romania mihai_brb

    I got this error when the Webform reference field is attached to a Paragraph - that is attached to a Node.
    Patch works.

  • Status changed to Active over 2 years ago
  • Status changed to Needs work about 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    The patch is most likely suppressing a larger issue with how the last submission is being determined.

    We need to come up with simpler steps to reproduce the issue.

  • Status changed to Closed: duplicate about 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY
  • Status changed to Active about 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    I think #5 is catching that the issue has something to do with a webform embed via paragraph is not determining the correct source entity.

    Paragraphs have become an ongoing challenge, and adjusting any of the existing logic without causing regressions is tough.

  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY
  • πŸ‡ΊπŸ‡ΈUnited States gcb

    I have the same issue, manifesting when I load up the layout builder configuration for a view mode for the entity.

  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    The proposed fix causes the switch/case to fall through to the next switch.

          case WebformMessageManagerInterface::PREVIOUS_SUBMISSION:
             $webform_submission = $this->getSubmissionStorage()->getLastSubmission($webform, $source_entity, $this->currentUser);
    -        $args = [':href' => $this->requestHandler->getUrl($webform_submission, $source_entity, 'webform.user.submission')->toString()];
    -        return $this->getCustomMessage('previous_submission_message', $args);
    +        if ($webform_submission) {
    +          $args = [':href' => $this->requestHandler->getUrl($webform_submission, $source_entity, 'webform.user.submission')->toString()];
    +          return $this->getCustomMessage('previous_submission_message', $args);
    +        }
     
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY
  • πŸ‡¦πŸ‡ΉAustria tgoeg

    Hi!

    I'm seeing this as well and I think I have a little more details that might help debugging:

    It boils down to these two SQL queries (the self join seems irrelevant, but I'll leave it here as this is just how it got generated):

    SELECT base_table.sid AS "sid", base_table.sid AS base_table_sid
    FROM
    webform_submission AS base_table
    INNER JOIN webform_submission AS webform_submission ON webform_submission.sid = base_table.sid
    WHERE
        (webform_submission.webform_id = "gutachten")
        AND (webform_submission.entity_type LIKE "node" ESCAPE '\\')
        AND (webform_submission.entity_id LIKE "45" ESCAPE '\\')
        AND (webform_submission.uid = "2")
        AND (webform_submission.in_draft = 0)
    ORDER BY base_table.sid DESC
    LIMIT 1 OFFSET 0
    
    SELECT base_table.sid AS "sid", base_table.sid AS base_table_sid
    FROM
    webform_submission AS base_table
    INNER JOIN webform_submission AS webform_submission ON webform_submission.sid = base_table.sid
    WHERE
        (webform_submission.webform_id = "gutachten")
        AND (webform_submission.entity_type LIKE "paragraph" ESCAPE '\\')
        AND (webform_submission.entity_id LIKE "2" ESCAPE '\\')
        AND (webform_submission.uid = "2")
        AND (webform_submission.in_draft = 0)
    ORDER BY base_table.sid DESC
    LIMIT 1 OFFSET 0

    The former one gives me my last submission, whereas the latter one yields NULL, which causes the HTTP 500.

    In the first round
    WebFormSubmissionForm->buildForm
    uses
    ->displayMessages,
    WebFormSubmissionForm->sourceEntity is "node" in this case.

    It then calls ->getLastSubmission, finds a submission and wants to display the message. This is the first SQL query, it returns an entry.

    The getMessageManager() part then again uses the entity in setWebformSubmission() (set, not get!), but this time the entity is "paragraph", and there are no submissions as this yields a NULL in the SQL query.

    I guess the problem is that the two calls should use the same entity ID, but I could not dig any deeper to find out why they don't.
    Maybe this helps you to debug this further?

    These might be the steps to reproduce it:
    I think you need to have submissions when using the webform as a block, then add it in a paragraph and load the page with the same user that has a submission from before.
    "Show the notification about previous submissions" needs to be enabled for the form.
    This seems to trigger the error.

    Another webform on the same page works flawlessly in a paragraph, so I think I can rule out paragraphs as the sole culprit. It seems to be the switch in where it is/was embedded and whether there are past submissions.
    If I disable "Show the notification about previous submissions" in the config, the error is gone as well (pretty much expected).

  • πŸ‡©πŸ‡ͺGermany hexabinaer Berlin, Germany

    Manage display > Set submission source entity: No suppresses the fatal error, too. Just in case it helps digging.

Production build 0.71.5 2024