You are here

public function YamlFormMessageManager::get in YAML Form 8

Get message.

Parameters

string $key: The name of form settings message to be displayed.

Return value

string|bool A message or FALSE if no message is found.

Overrides YamlFormMessageManagerInterface::get

1 call to YamlFormMessageManager::get()
YamlFormMessageManager::build in src/YamlFormMessageManager.php
Build message.

File

src/YamlFormMessageManager.php, line 171

Class

YamlFormMessageManager
Defines the form message (and login) manager.

Namespace

Drupal\yamlform

Code

public function get($key) {
  $yamlform_settings = $this->yamlform ? $this->yamlform
    ->getSettings() : [];
  $entity = $this->yamlformSubmission ?: $this->yamlform;
  if (!empty($yamlform_settings[$key])) {
    return $this->tokenManager
      ->replace($yamlform_settings[$key], $entity);
  }
  $default_settings = $this->configFactory
    ->get('yamlform.settings')
    ->get('settings');
  if (!empty($default_settings['default_' . $key])) {
    return $this->tokenManager
      ->replace($default_settings['default_' . $key], $entity);
  }
  $yamlform = $this->yamlform;
  $source_entity = $this->sourceEntity;
  $t_args = [
    '%form' => $source_entity ? $source_entity
      ->label() : $yamlform
      ->label(),
    ':handlers_href' => $yamlform
      ->toUrl('handlers-form')
      ->toString(),
    ':settings_href' => $yamlform
      ->toUrl('settings-form')
      ->toString(),
    ':duplicate_href' => $yamlform
      ->toUrl('duplicate-form')
      ->toString(),
  ];
  switch ($key) {
    case YamlFormMessageManagerInterface::ADMIN_ACCESS:
      return $this
        ->t('This form is <a href=":settings_href">closed</a>. Only submission administrators are allowed to access this form and create new submissions.', $t_args);
    case YamlFormMessageManagerInterface::SUBMISSION_DEFAULT_CONFIRMATION:
      return $this
        ->t('New submission added to %form.', $t_args);
    case YamlFormMessageManagerInterface::FORM_SAVE_EXCEPTION:
      return $this
        ->t('This form is currently not saving any submitted data. Please enable the <a href=":settings_href">saving of results</a> or add a <a href=":handlers_href">submission handler</a> to the form.', $t_args);
    case YamlFormMessageManagerInterface::SUBMISSION_PREVIOUS:
      $yamlform_submission = $this->entityStorage
        ->getLastSubmission($yamlform, $source_entity, $this->currentUser);
      $submission_route_name = $this->requestHandler
        ->getRouteName($yamlform_submission, $source_entity, 'yamlform.user.submission');
      $submission_route_parameters = $this->requestHandler
        ->getRouteParameters($yamlform_submission, $source_entity);
      $t_args[':submission_href'] = Url::fromRoute($submission_route_name, $submission_route_parameters)
        ->toString();
      return $this
        ->t('You have already submitted this form.') . ' ' . $this
        ->t('<a href=":submission_href">View your previous submission</a>.', $t_args);
    case YamlFormMessageManagerInterface::SUBMISSIONS_PREVIOUS:
      $submissions_route_name = $this->requestHandler
        ->getRouteName($yamlform, $source_entity, 'yamlform.user.submissions');
      $submissions_route_parameters = $this->requestHandler
        ->getRouteParameters($yamlform, $source_entity);
      $t_args[':submissions_href'] = Url::fromRoute($submissions_route_name, $submissions_route_parameters)
        ->toString();
      return $this
        ->t('You have already submitted this form.') . ' ' . $this
        ->t('<a href=":submissions_href">View your previous submissions</a>.', $t_args);
    case YamlFormMessageManagerInterface::SUBMISSION_UPDATED:
      return $this
        ->t('Submission updated in %form.', $t_args);
    case YamlFormMessageManagerInterface::SUBMISSION_TEST:
      return $this
        ->t("The below form has been prepopulated with custom/random test data. When submitted, this information <strong>will still be saved</strong> and/or <strong>sent to designated recipients</strong>.", $t_args);
    case YamlFormMessageManagerInterface::TEMPLATE_PREVIEW:
      return $this
        ->t('You are previewing the below template, which can be used to <a href=":duplicate_href">create a new form</a>. <strong>Submitted data will be ignored</strong>.', $t_args);
    default:
      return FALSE;
  }
}