function template_preprocess_yamlform_submission_text in YAML Form 8
Prepares variables for form submission plain text template.
Default template: yamlform-submission-text.html.twig.
Parameters
array $variables: An associative array containing the following key:
- yamlform_submission: A form submission.
File
- includes/
yamlform.theme.inc, line 345 - Preprocessors and helper functions to make theming easier.
Code
function template_preprocess_yamlform_submission_text(array &$variables) {
/** @var \Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission */
$yamlform_submission = $variables['yamlform_submission'];
$variables['sid'] = $yamlform_submission
->id();
$variables['uuid'] = $yamlform_submission
->uuid();
$variables['is_draft'] = $yamlform_submission
->isDraft() ? t('Yes') : t('No');
$variables['current_page'] = $yamlform_submission
->getCurrentPage();
$variables['remote_addr'] = $yamlform_submission
->getRemoteAddr();
$variables['submitted_by'] = $yamlform_submission
->getOwner()
->label();
$variables['form'] = $yamlform_submission
->getYamlForm()
->label();
$variables['created'] = YamlFormDateHelper::format($yamlform_submission
->getCreatedTime());
$variables['completed'] = YamlFormDateHelper::format($yamlform_submission
->getCompletedTime());
$variables['changed'] = YamlFormDateHelper::format($yamlform_submission
->getChangedTime());
// @see \Drupal\Core\Field\Plugin\Field\FieldFormatter\LanguageFormatter::viewValue()
$languages = \Drupal::languageManager()
->getNativeLanguages();
$langcode = $yamlform_submission
->get('langcode')->value;
$variables['language'] = isset($languages[$langcode]) ? $languages[$langcode]
->getName() : $langcode;
if ($source_url = $yamlform_submission
->getSourceUrl()) {
$variables['uri'] = $source_url
->toString();
}
if ($source_entity = $yamlform_submission
->getSourceEntity()) {
$variables['submitted_to'] = $source_entity
->label();
}
/** @var \Drupal\yamlform\YamlFormSubmissionViewBuilderInterface $view_builder */
$view_builder = \Drupal::entityTypeManager()
->getViewBuilder('yamlform_submission');
$yamlform = $yamlform_submission
->getYamlForm();
$data = $yamlform_submission
->getData();
$elements = $yamlform
->getElementsInitialized();
$variables['data'] = $view_builder
->buildElements($elements, $data, [], 'text');
}