0

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

4

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 Jan 31 at 14:51
  • Try $submission->toLink()->toRenderable() – user89751 Feb 1 at 9:03
0

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, privacy policy and cookie policy

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