function template_preprocess_yamlform_submission_navigation in YAML Form 8
Prepares variables for form submission navigation templates.
Default template: yamlform-submission-navigation.html.twig.
Parameters
array $variables: An associative array containing the following key:
- yamlform_submission: A form submission.
- rel: Form submission link template. (canonical, edit-form, resend-form, html, text, or yaml).
File
- includes/
yamlform.theme.inc, line 193 - Preprocessors and helper functions to make theming easier.
Code
function template_preprocess_yamlform_submission_navigation(array &$variables) {
/** @var \Drupal\yamlform\YamlFormRequestInterface $request_handler */
$request_handler = \Drupal::service('yamlform.request');
/** @var \Drupal\yamlform\YamlFormSubmissionStorageInterface $yamlform_submission_storage */
$yamlform_submission_storage = \Drupal::entityTypeManager()
->getStorage('yamlform_submission');
/** @var \Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission */
$yamlform_submission = $variables['yamlform_submission'];
// Get the route name, parameters, and source entity for the current page.
// This ensures that the user stays within their current context as they are
// paging through submission.
$route_name = \Drupal::routeMatch()
->getRouteName();
$route_parameters = \Drupal::routeMatch()
->getRawParameters()
->all();
$source_entity = $request_handler
->getCurrentSourceEntity([
'yamlform_submission',
]);
if (strpos(\Drupal::routeMatch()
->getRouteName(), 'yamlform.user.submission') !== FALSE) {
$account = \Drupal::currentUser();
}
else {
$account = NULL;
}
if ($previous_submission = $yamlform_submission_storage
->getPreviousSubmission($yamlform_submission, $source_entity, $account)) {
$variables['prev_url'] = Url::fromRoute($route_name, [
'yamlform_submission' => $previous_submission
->id(),
] + $route_parameters)
->toString();
}
if ($next_submission = $yamlform_submission_storage
->getNextSubmission($yamlform_submission, $source_entity, $account)) {
$variables['next_url'] = Url::fromRoute($route_name, [
'yamlform_submission' => $next_submission
->id(),
] + $route_parameters)
->toString();
}
$variables['#attached']['library'][] = 'yamlform/yamlform.navigation';
}