class YamlFormSubmissionResendForm in YAML Form 8
Defines a form that resends form submission.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\yamlform\Form\YamlFormSubmissionResendForm
Expanded class hierarchy of YamlFormSubmissionResendForm
2 string references to 'YamlFormSubmissionResendForm'
- yamlform.routing.yml in ./
yamlform.routing.yml - yamlform.routing.yml
- yamlform_node.routing.yml in modules/
yamlform_node/ yamlform_node.routing.yml - modules/yamlform_node/yamlform_node.routing.yml
File
- src/
Form/ YamlFormSubmissionResendForm.php, line 15
Namespace
Drupal\yamlform\FormView source
class YamlFormSubmissionResendForm extends FormBase {
/**
* A form submission.
*
* @var \Drupal\yamlform\YamlFormSubmissionInterface
*/
protected $yamlformSubmission;
/**
* The source entity.
*
* @var \Drupal\Core\Entity\EntityInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'yamlform_submission_resend';
}
/**
* Form request handler.
*
* @var \Drupal\yamlform\YamlFormRequestInterface
*/
protected $requestHandler;
/**
* Constructs a new YamlFormResultsDeleteBaseForm object.
*
* @param \Drupal\yamlform\YamlFormRequestInterface $request_handler
* The form request handler.
*/
public function __construct(YamlFormRequestInterface $request_handler) {
$this->requestHandler = $request_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('yamlform.request'));
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, YamlFormSubmissionInterface $yamlform_submission = NULL) {
$this->yamlformSubmission = $yamlform_submission;
$handlers = $yamlform_submission
->getYamlForm()
->getHandlers();
/** @var \Drupal\yamlform\YamlFormHandlerMessageInterface[] $message_handlers */
$message_handlers = [];
foreach ($handlers as $handler_id => $handler) {
if ($handler instanceof EmailYamlFormHandler) {
$message_handlers[$handler_id] = $handler;
}
}
// Get header.
$header = [];
$header['title'] = [
'data' => $this
->t('Title / Description'),
];
$header['id'] = [
'data' => $this
->t('ID'),
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
];
$header['summary'] = [
'data' => $this
->t('summary'),
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
];
$header['status'] = [
'data' => $this
->t('Status'),
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
];
// Get options.
$options = [];
foreach ($message_handlers as $index => $message_handler) {
$message = $message_handler
->getMessage($this->yamlformSubmission);
$options[$index]['title'] = [
'data' => [
'label' => [
'#type' => 'label',
'#title' => $message_handler
->label() . ': ' . $message_handler
->description(),
'#title_display' => NULL,
'#for' => 'edit-message-handler-id-' . str_replace('_', '-', $message_handler
->getHandlerId()),
],
],
];
$options[$index]['id'] = [
'data' => $message_handler
->getHandlerId(),
];
$options[$index]['summary'] = [
'data' => $message_handler
->getMessageSummary($message),
];
$options[$index]['status'] = $message_handler
->isEnabled() ? $this
->t('Enabled') : $this
->t('Disabled');
}
// Get message handler id.
if (empty($form_state
->getValue('message_handler_id'))) {
reset($options);
$message_handler_id = key($options);
$form_state
->setValue('message_handler_id', $message_handler_id);
}
else {
$message_handler_id = $form_state
->getValue('message_handler_id');
}
$message_handler = $this
->getMessageHandler($form_state);
$form['message_handler_id'] = [
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#js_select' => TRUE,
'#empty' => $this
->t('No messages are available.'),
'#multiple' => FALSE,
'#default_value' => $message_handler_id,
'#ajax' => [
'callback' => '::updateMessage',
'wrapper' => 'edit-yamlform-message-wrapper',
],
];
// Message.
$form['message'] = [
'#type' => 'details',
'#title' => $this
->t('Message'),
'#open' => TRUE,
'#tree' => TRUE,
'#prefix' => '<div id="edit-yamlform-message-wrapper">',
'#suffix' => '</div>',
];
$message = $message_handler
->getMessage($yamlform_submission);
$form['message'] += $message_handler
->resendMessageForm($message);
// Add resend button.
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Resend message'),
];
// Add submission navigation.
$source_entity = $this->requestHandler
->getCurrentSourceEntity('yamlform_submission');
$form['navigation'] = [
'#theme' => 'yamlform_submission_navigation',
'#yamlform_submission' => $yamlform_submission,
'#weight' => -20,
];
$form['information'] = [
'#theme' => 'yamlform_submission_information',
'#yamlform_submission' => $yamlform_submission,
'#source_entity' => $source_entity,
'#weight' => -19,
];
$form['#attached']['library'][] = 'yamlform/yamlform.admin';
return $form;
}
/**
* Handles switching between messages.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* An associative array containing an email message.
*/
public function updateMessage(array $form, FormStateInterface $form_state) {
$message_handler = $this
->getMessageHandler($form_state);
$message = $message_handler
->getMessage($this->yamlformSubmission);
foreach ($message as $key => $value) {
$form['message'][$key]['#value'] = $value;
}
return $form['message'];
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$params = $form_state
->getValue('message');
$message_handler = $this
->getMessageHandler($form_state);
$message_handler
->sendMessage($params);
$t_args = [
'%label' => $message_handler
->label(),
];
drupal_set_message($this
->t('Successfully re-sent %label.', $t_args));
}
/**
* Get message handler from form state.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return \Drupal\yamlform\YamlFormHandlerMessageInterface
* The current message handler.
*/
protected function getMessageHandler(FormStateInterface $form_state) {
$message_handler_id = $form_state
->getValue('message_handler_id');
return $this->yamlformSubmission
->getYamlForm()
->getHandler($message_handler_id);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator 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. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
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. | 1 |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
YamlFormSubmissionResendForm:: |
protected | property | The source entity. | |
YamlFormSubmissionResendForm:: |
protected | property | Form request handler. | |
YamlFormSubmissionResendForm:: |
protected | property | A form submission. | |
YamlFormSubmissionResendForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
YamlFormSubmissionResendForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
YamlFormSubmissionResendForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
YamlFormSubmissionResendForm:: |
protected | function | Get message handler from form state. | |
YamlFormSubmissionResendForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
YamlFormSubmissionResendForm:: |
public | function | Handles switching between messages. | |
YamlFormSubmissionResendForm:: |
public | function | Constructs a new YamlFormResultsDeleteBaseForm object. |