You are here

function yamlform_token_info in YAML Form 8

Implements hook_token_info().

File

./yamlform.tokens.inc, line 16
Builds placeholder replacement tokens for forms and submissions.

Code

function yamlform_token_info() {
  $types = [];
  $types['yamlform-authenticated-user'] = [
    'name' => t('Form authenticated user'),
    'description' => t('Tokens related to the currently authenticated user.'),
    'type' => 'user',
  ];
  $types['yamlform_submission'] = [
    'name' => t('Form submissions'),
    'description' => t('Tokens related to form submission.'),
    'needs-data' => 'yamlform_submission',
  ];
  $types['yamlform'] = [
    'name' => t('Forms'),
    'description' => t('Tokens related to forms.'),
    'needs-data' => 'yamlform',
  ];

  // Submission related variables.
  $yamlform_submission = [];
  $yamlform_submission['serial'] = [
    'name' => t('Submission serial number'),
    'description' => t('The serial number of the form submission .'),
  ];
  $yamlform_submission['sid'] = [
    'name' => t('Submission ID'),
    'description' => t('The ID of the form submission .'),
  ];
  $yamlform_submission['uuid'] = [
    'name' => t('UUID'),
    'description' => t('The UUID of the form submission.'),
  ];
  $yamlform_submission['token'] = [
    'name' => t('Token'),
    'description' => t('A secure token used to look up a submission.'),
  ];
  $yamlform_submission['ip-address'] = [
    'name' => t('IP address'),
    'description' => t('The IP address that was used when submitting the form submission.'),
  ];
  $yamlform_submission['source-url'] = [
    'name' => t('Source URL'),
    'description' => t('The URL the user submitted the form submission.'),
  ];
  $yamlform_submission['update-url'] = [
    'name' => t('Update URL'),
    'description' => t('The URL that can used to update the form submission. The form must be configurated to allow users to update a submission using a secure token.'),
  ];
  $yamlform_submission['langcode'] = [
    'name' => t('Langcode'),
    'description' => t('The language code of the form submission.'),
  ];
  $yamlform_submission['language'] = [
    'name' => t('Language'),
    'description' => t('The language name of the the form submission.'),
  ];

  // Dynamic tokens for form submissions.
  $yamlform_submission['url'] = [
    'name' => t('URL'),
    'description' => t("The URL of the form submission. Replace the '?' with the link template. Defaults to 'canonical' which displays the submission's data."),
    'dynamic' => TRUE,
  ];
  $yamlform_submission['values'] = [
    'name' => t('Submission values'),
    'description' => t("Form tokens from submitted data. Replace the '?' with the 'element_key' or 'element_key:format'.") . ' ' . t("The 'format' can be 'value', 'raw', or custom format specifically associated with the element") . ' ' . t("For example, to display the Contact form's 'Subject' element's value you would use the [yamlform_submission:values:subject] token."),
    'dynamic' => TRUE,
  ];

  // Chained tokens for form submissions.
  $yamlform_submission['user'] = [
    'name' => t('Submitter'),
    'description' => t('The user that submitted the form submission.'),
    'type' => 'user',
  ];
  $yamlform_submission['created'] = [
    'name' => t('Date created'),
    'description' => t('The date the form submission was created.'),
    'type' => 'date',
  ];
  $yamlform_submission['completed'] = [
    'name' => t('Date completed'),
    'description' => t('The date the form submission was completed.'),
    'type' => 'date',
  ];
  $yamlform_submission['changed'] = [
    'name' => t('Date changed'),
    'description' => t('The date the form submission was most recently updated.'),
    'type' => 'date',
  ];
  $yamlform_submission['yamlform'] = [
    'name' => t('Form'),
    'description' => t('The form that the form submission belongs to.'),
    'type' => 'yamlform',
  ];
  $yamlform_submission['source-entity'] = [
    'name' => t('Source entity'),
    'description' => t('The source entity that the form submission was submitted from.'),
    'type' => 'entity',
  ];

  // Form related variables.
  $yamlform = [];
  $yamlform['id'] = [
    'name' => t('Form ID'),
    'description' => t('The ID of the form.'),
  ];
  $yamlform['title'] = [
    'name' => t('title'),
    'description' => t('The title of the form.'),
  ];
  $yamlform['description'] = [
    'name' => t('Description'),
    'description' => t('The administrative description of the form.'),
  ];
  $yamlform['url'] = [
    'name' => t('URL'),
    'description' => t('The URL of the form.'),
  ];
  $yamlform['author'] = [
    'name' => t('Author'),
    'type' => 'user',
  ];
  return [
    'types' => $types,
    'tokens' => [
      'yamlform_submission' => $yamlform_submission,
      'yamlform' => $yamlform,
    ],
  ];
}