class WebformSubmissionController in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Controller/WebformSubmissionController.php \Drupal\webform\Controller\WebformSubmissionController
Provides route responses for Webform submissions.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\webform\Controller\WebformSubmissionController
Expanded class hierarchy of WebformSubmissionController
1 file declares its use of WebformSubmissionController
File
- src/
Controller/ WebformSubmissionController.php, line 18
Namespace
Drupal\webform\ControllerView source
class WebformSubmissionController extends ControllerBase {
/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* The webform request handler.
*
* @var \Drupal\webform\WebformRequestInterface
*/
protected $requestHandler;
/**
* The webform token manager.
*
* @var \Drupal\webform\WebformTokenManagerInterface
*/
protected $tokenManager;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
$instance = parent::create($container);
$instance->renderer = $container
->get('renderer');
$instance->requestHandler = $container
->get('webform.request');
$instance->tokenManager = $container
->get('webform.token_manager');
return $instance;
}
/**
* Toggle webform submission sticky.
*
* @param \Drupal\webform\WebformSubmissionInterface $webform_submission
* A webform submission.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An Ajax response that toggle the sticky icon.
*/
public function sticky(WebformSubmissionInterface $webform_submission) {
// Toggle sticky.
$webform_submission
->setSticky(!$webform_submission
->isSticky())
->save();
// Get selector.
$selector = '#webform-submission-' . $webform_submission
->id() . '-sticky';
$response = new AjaxResponse();
// Update sticky.
$response
->addCommand(new HtmlCommand($selector, static::buildSticky($webform_submission)));
// Announce sticky status.
$t_args = [
'@label' => $webform_submission
->label(),
];
$text = $webform_submission
->isSticky() ? $this
->t('@label flagged/starred.', $t_args) : $this
->t('@label unflagged/unstarred.', $t_args);
$response
->addCommand(new AnnounceCommand($text));
return $response;
}
/**
* Toggle webform submission locked.
*
* @param \Drupal\webform\WebformSubmissionInterface $webform_submission
* A webform submission.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An Ajax response that toggle the lock icon.
*/
public function locked(WebformSubmissionInterface $webform_submission) {
// Toggle locked.
$webform_submission
->setLocked(!$webform_submission
->isLocked())
->save();
// Get selector.
$selector = '#webform-submission-' . $webform_submission
->id() . '-locked';
$response = new AjaxResponse();
// Update lock.
$response
->addCommand(new HtmlCommand($selector, static::buildLocked($webform_submission)));
// Announce lock status.
$t_args = [
'@label' => $webform_submission
->label(),
];
$text = $webform_submission
->isLocked() ? $this
->t('@label locked.', $t_args) : $this
->t('@label unlocked.', $t_args);
$response
->addCommand(new AnnounceCommand($text));
return $response;
}
/**
* Build sticky icon.
*
* @param \Drupal\webform\WebformSubmissionInterface $webform_submission
* A webform submission.
*
* @return \Drupal\Component\Render\FormattableMarkup
* Sticky icon.
*/
public static function buildSticky(WebformSubmissionInterface $webform_submission) {
$t_args = [
'@label' => $webform_submission
->label(),
];
$args = [
'@state' => $webform_submission
->isSticky() ? 'on' : 'off',
'@label' => $webform_submission
->isSticky() ? t('Unstar/Unflag @label', $t_args) : t('Star/flag @label', $t_args),
];
return new FormattableMarkup('<span class="webform-icon webform-icon-sticky webform-icon-sticky--@state"></span><span class="visually-hidden">@label</span>', $args);
}
/**
* Build locked icon.
*
* @param \Drupal\webform\WebformSubmissionInterface $webform_submission
* A webform submission.
*
* @return \Drupal\Component\Render\FormattableMarkup
* Locked icon.
*/
public static function buildLocked(WebformSubmissionInterface $webform_submission) {
$t_args = [
'@label' => $webform_submission
->label(),
];
$args = [
'@state' => $webform_submission
->isLocked() ? 'on' : 'off',
'@label' => $webform_submission
->isLocked() ? t('Unlock @label', $t_args) : t('Lock @label', $t_args),
];
return new FormattableMarkup('<span class="webform-icon webform-icon-lock webform-icon-locked--@state"></span><span class="visually-hidden">@label</span>', $args);
}
/**
* Returns a webform submissions's access denied page.
*
* @param \Drupal\webform\WebformInterface $webform
* The webform.
* @param \Drupal\webform\WebformSubmissionInterface $webform_submission
* A webform submission.
*
* @return array
* A renderable array containing an access denied page.
*/
public function accessDenied(WebformInterface $webform, WebformSubmissionInterface $webform_submission) {
// Message.
$config = $this
->config('webform.settings');
$message = $webform
->getSetting('submission_access_denied_message') ?: $config
->get('settings.default_submission_access_denied_message');
$message = $this->tokenManager
->replace($message, $webform_submission);
// Attributes.
$attributes = $webform
->getSetting('submission_access_denied_attributes');
$attributes['class'][] = 'webform-submission-access-denied';
// Build message.
$build = [
'#type' => 'container',
'#attributes' => $attributes,
'message' => WebformHtmlEditor::checkMarkup($message),
];
// Add config and webform to cache contexts.
$this->renderer
->addCacheableDependency($build, $config);
$this->renderer
->addCacheableDependency($build, $webform);
return $build;
}
/**
* Returns a webform 's access denied title.
*
* @param \Drupal\webform\WebformInterface $webform
* The webform.
*
* @return string|\Drupal\Core\StringTranslation\TranslatableMarkup
* The webform's access denied title.
*/
public function accessDeniedTitle(WebformInterface $webform) {
return $webform
->getSetting('submission_access_denied_title') ?: $this
->t('Access denied');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function | Returns a redirect response object for the specified route. | |
ControllerBase:: |
protected | function | Returns the state storage service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
WebformSubmissionController:: |
protected | property | The renderer service. | |
WebformSubmissionController:: |
protected | property | The webform request handler. | |
WebformSubmissionController:: |
protected | property | The webform token manager. | |
WebformSubmissionController:: |
public | function | Returns a webform submissions's access denied page. | |
WebformSubmissionController:: |
public | function | Returns a webform 's access denied title. | |
WebformSubmissionController:: |
public static | function | Build locked icon. | |
WebformSubmissionController:: |
public static | function | Build sticky icon. | |
WebformSubmissionController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
WebformSubmissionController:: |
public | function | Toggle webform submission locked. | |
WebformSubmissionController:: |
public | function | Toggle webform submission sticky. |