You are here

function template_preprocess_yamlform_submission_information in YAML Form 8

Prepares variables for form submission information template.

Default template: yamlform-submission-information.html.twig.

Parameters

array $variables: An associative array containing the following key:

  • yamlform_submission: A form submission.

File

includes/yamlform.theme.inc, line 235
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_yamlform_submission_information(array &$variables) {

  /** @var \Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission */
  $yamlform_submission = $variables['yamlform_submission'];
  $yamlform = $yamlform_submission
    ->getYamlForm();
  $variables['yamlform_id'] = $yamlform
    ->id();
  $variables['serial'] = $yamlform_submission
    ->serial();
  $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
    ->getCurrentPageTitle();
  $variables['remote_addr'] = $yamlform_submission
    ->getRemoteAddr();
  $variables['submitted_by'] = $yamlform_submission
    ->getOwner()
    ->toLink();
  $variables['form'] = $yamlform
    ->toLink();
  $variables['created'] = YamlFormDateHelper::format($yamlform_submission
    ->getCreatedTime());
  $variables['completed'] = YamlFormDateHelper::format($yamlform_submission
    ->getCompletedTime());
  $variables['changed'] = YamlFormDateHelper::format($yamlform_submission
    ->getChangedTime());
  $variables['sticky'] = $yamlform_submission
    ->isSticky() ? t('Yes') : '';
  $variables['notes'] = $yamlform_submission
    ->getNotes();

  // @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'] = Link::fromTextAndUrl($source_url
      ->setAbsolute(FALSE)
      ->toString(), $source_url);
  }
  if ($yamlform
    ->getSetting('token_update')) {
    $token_url = $yamlform_submission
      ->getTokenUrl();
    $variables['token_update'] = Link::fromTextAndUrl($token_url
      ->setAbsolute(FALSE)
      ->toString(), $token_url);
  }
  if ($source_entity = $yamlform_submission
    ->getSourceEntity()) {
    $variables['submitted_to'] = $source_entity
      ->toLink();
  }
  $variables['submissions_view'] = FALSE;
  if ($yamlform
    ->access('submission_view_any')) {
    $variables['submissions_view'] = TRUE;
  }
  elseif ($source_entity) {
    $entity_type = $source_entity
      ->getEntityTypeId();
    if (\Drupal::currentUser()
      ->hasPermission("view yamlform node submissions any {$entity_type}")) {
      $variables['submissions_view'] = TRUE;
    }
    elseif (\Drupal::currentUser()
      ->hasPermission("view yamlform node submissions own {$entity_type}") && method_exists($source_entity, 'getOwnerId') && $source_entity
      ->getOwnerId() == \Drupal::currentUser()
      ->id()) {
      $variables['submissions_view'] = TRUE;
    }
  }
}