I have managed to create a table of webform submissions of a particular type, thanks to the answer from a question posted here. What I would like to do now is add a link for each webform submission, and I can't figure out how.

I tried looking through the API, and found a toUrl function, but I don't understand how to use it to get the link for each webform submission. Once I have the link, I would like to combine it with the rest of its info in submission_data[] for display in the table.

Thanks in advance!

$query = \Drupal::entityQuery('webform_submission')
  ->condition('webform_id', 'sign_up');
$result = $query->execute(); // Gives me IDs associated with the "sign_up" webform.

$storage = \Drupal::entityTypeManager()->getStorage('webform_submission');
$submissions = $storage->loadMultiple($result);
$submission_data = array();
foreach ($submissions as $submission) {
  $submission_data[] = $submission->getData();
// $submission_data now contains all the submissions from "sign_up" webform.

How do I add a link to the webform submission? When I look through submission_data[] it doesn't contain the ID of the webform submission

2 Answers 2


Webform submissions are content entities, you can use any method defined in \Drupal\Core\Entity\EntityInterface including…

  • Thanks for your answer! I'm still stuck. When I try to add $submission->toLink() I get the error 'Drupal\Core\Link could not be converted to string' - how do I get it to print to the page in my table? Thanks again for your help.
    – pinkninja
    Commented Jan 31, 2019 at 14:51
  • Try $submission->toLink()->toRenderable()
    – user89751
    Commented Feb 1, 2019 at 9:03
  • $url = $submission->toLink('#' . $submission->id(), 'canonical', ['absolute' => TRUE, 'attributes' => ['target' => '_blank'],])->toString();
    – leymannx
    Commented Oct 21, 2020 at 13:36
  • 1
    $url = \Drupal\Core\Link::createFromRoute('#' . $submission->serial(), 'entity.webform.user.submission', ['webform' => $submission->getWebform()->id(), 'webform_submission' => $submission->id()], ['absolute' => TRUE, 'attributes' => ['target' => '_blank']])->toString();
    – leymannx
    Commented Oct 21, 2020 at 20:12

To get this working, I needed to use what jrockowitz suggested in his answer and also add toString() to get it to display properly in the table.

Without toString(), it gave me an error (Drupal\Core\Link could not be converted to string), because toUrl() returns an object rather than the url itself)

$url = $submission->toUrl()->toString();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.