public function WebformMessageManager::get in Webform 6.x
Same name and namespace in other branches
- 8.5 src/WebformMessageManager.php \Drupal\webform\WebformMessageManager::get()
Get message.
Parameters
string $key: The name of webform settings message to be displayed.
Return value
string|bool A message or FALSE if no message is found.
Overrides WebformMessageManagerInterface::get
1 call to WebformMessageManager::get()
- WebformMessageManager::build in src/
WebformMessageManager.php - Build message.
File
- src/
WebformMessageManager.php, line 225
Class
- WebformMessageManager
- Defines the webform message (and login) manager.
Namespace
Drupal\webformCode
public function get($key) {
// Get custom message from settings.
if ($custom_message = $this
->getCustomMessage($key)) {
return $custom_message;
}
$webform = $this->webform;
$source_entity = $this->sourceEntity;
// Get custom messages with :href argument.
switch ($key) {
case WebformMessageManagerInterface::DRAFT_PENDING_SINGLE:
$webform_draft = $this
->getSubmissionStorage()
->loadDraft($webform, $source_entity, $this->currentUser);
$args = [
':href' => $webform_draft
->getTokenUrl()
->toString(),
];
return $this
->getCustomMessage('draft_pending_single_message', $args);
case WebformMessageManagerInterface::DRAFT_PENDING_MULTIPLE:
$args = [
':href' => $this->requestHandler
->getUrl($webform, $source_entity, 'webform.user.drafts')
->toString(),
];
return $this
->getCustomMessage('draft_pending_multiple_message', $args);
case WebformMessageManagerInterface::PREVIOUS_SUBMISSION:
$webform_submission = $this
->getSubmissionStorage()
->getLastSubmission($webform, $source_entity, $this->currentUser);
$args = [
':href' => $this->requestHandler
->getUrl($webform_submission, $source_entity, 'webform.user.submission')
->toString(),
];
return $this
->getCustomMessage('previous_submission_message', $args);
case WebformMessageManagerInterface::PREVIOUS_SUBMISSIONS:
$args = [
':href' => $this->requestHandler
->getUrl($webform, $source_entity, 'webform.user.submissions')
->toString(),
];
return $this
->getCustomMessage('previous_submissions_message', $args);
}
// Get hard-coded messages.
switch ($key) {
case WebformMessageManagerInterface::ADMIN_PAGE:
return $this
->t('Only webform administrators are allowed to access this page and create new submissions.');
case WebformMessageManagerInterface::ADMIN_CLOSED:
$t_args = [
':href' => $webform
->toUrl('settings-form')
->toString(),
];
return $this
->t('This webform is <a href=":href">closed</a>. Only submission administrators are allowed to access this webform and create new submissions.', $t_args);
case WebformMessageManagerInterface::ADMIN_ARCHIVED:
$t_args = [
':href' => $webform
->toUrl('settings')
->toString(),
];
return $this
->t('This webform is <a href=":href">archived</a>. Only submission administrators are allowed to access this webform and create new submissions.', $t_args);
case WebformMessageManagerInterface::SUBMISSION_DEFAULT_CONFIRMATION:
$t_args = [
'%form' => $source_entity ? $source_entity
->label() : $webform
->label(),
];
return $this
->t('New submission added to %form.', $t_args);
case WebformMessageManagerInterface::FORM_SAVE_EXCEPTION:
$t_args = [
':handlers_href' => $webform
->toUrl('handlers')
->toString(),
':settings_href' => $webform
->toUrl('settings')
->toString(),
];
return $this
->t('This webform 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 webform.', $t_args);
case WebformMessageManagerInterface::HANDLER_SUBMISSION_REQUIRED:
$t_args = [
':href' => $webform
->toUrl('handlers')
->toString(),
];
return $this
->t('This webform\'s <a href=":href">submission handlers</a> requires submissions to be saved to the database.', $t_args);
case WebformMessageManagerInterface::SUBMISSION_UPDATED:
$t_args = [
'%form' => $source_entity ? $source_entity
->label() : $webform
->label(),
];
return $this
->t('Submission updated in %form.', $t_args);
case WebformMessageManagerInterface::SUBMISSION_TEST:
return $this
->t("The below webform 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>.");
case WebformMessageManagerInterface::TEMPLATE_PREVIEW:
$t_args = [
':href' => $webform
->toUrl('duplicate-form')
->toString(),
];
return $this
->t('You are previewing the below template, which can be used to <a href=":href">create a new webform</a>. <strong>Submitted data will be ignored</strong>.', $t_args);
case WebformMessageManagerInterface::PREPOPULATE_SOURCE_ENTITY_TYPE:
case WebformMessageManagerInterface::PREPOPULATE_SOURCE_ENTITY_REQUIRED:
return $this
->t('This webform is not available. Please contact the site administrator.');
case WebformMessageManagerInterface::PREVIOUS_SUBMISSION:
$webform_submission = $this
->getSubmissionStorage()
->getLastSubmission($webform, $source_entity, $this->currentUser);
$args = [
':href' => $this->requestHandler
->getUrl($webform_submission, $source_entity, 'webform.user.submission')
->toString(),
];
return $this
->getCustomMessage('previous_submission_message', $args);
case WebformMessageManagerInterface::PREVIOUS_SUBMISSIONS:
$args = [
':href' => $this->requestHandler
->getUrl($webform, $source_entity, 'webform.user.submissions')
->toString(),
];
return $this
->getCustomMessage('previous_submissions_message', $args);
}
return FALSE;
}