public function WebformSubmissionDevelGenerateTrait::settingsForm in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/DevelGenerate/WebformSubmissionDevelGenerateTrait.php \Drupal\webform\Plugin\DevelGenerate\WebformSubmissionDevelGenerateTrait::settingsForm()
File
- src/
Plugin/ DevelGenerate/ WebformSubmissionDevelGenerateTrait.php, line 94
Class
- WebformSubmissionDevelGenerateTrait
- Provides a WebformSubmissionDevelGenerate plugin.
Namespace
Drupal\webform\Plugin\DevelGenerateCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$form['message'] = [
'#type' => 'webform_message',
'#message_message' => $this
->t('Please note that no emails will be sent while generating webform submissions.'),
'#message_type' => 'warning',
];
$options = [];
foreach ($this
->getWebformStorage()
->loadMultiple() as $webform) {
$options[$webform
->id()] = $webform
->label();
}
$webform_id = $this->request
->get('webform_id');
$source_entity_type = $this->request
->get('entity_type');
$source_entity_id = $this->request
->get('entity_id');
$source_entity = $source_entity_type && $source_entity_id ? $this
->getEntityStorage($source_entity_type)
->load($source_entity_id) : NULL;
if ($webform_id && isset($options[$webform_id])) {
$form['webform_ids'] = [
'#type' => 'value',
'#value' => [
$webform_id => $webform_id,
],
];
$form['webform'] = [
'#type' => 'item',
'#title' => $this
->t('Webform'),
'#markup' => $options[$webform_id],
];
}
else {
$form['webform_ids'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Webform'),
'#description' => $this
->t('Restrict submissions to these webforms.'),
'#required' => TRUE,
'#options' => $options,
];
}
if ($source_entity) {
$form['submitted'] = [
'#type' => 'item',
'#title' => $this
->t('Submitted to'),
'#markup' => $source_entity
->toLink()
->toString(),
];
$form['entity-type'] = [
'#type' => 'value',
'#value' => $source_entity_type,
];
$form['entity-id'] = [
'#type' => 'value',
'#value' => $source_entity_id,
];
}
elseif ($webform_id && isset($options[$webform_id])) {
$form['entity-type'] = [
'#type' => 'value',
'#value' => '',
];
$form['entity-id'] = [
'#type' => 'value',
'#value' => '',
];
}
else {
$entity_types = \Drupal::service('entity_type.repository')
->getEntityTypeLabels(TRUE);
$form['submitted'] = [
'#type' => 'item',
'#title' => $this
->t('Submitted to'),
];
$form['submitted']['container'] = [
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
];
$form['submitted']['container']['entity-type'] = [
'#type' => 'select',
'#title' => $this
->t('Entity type'),
'#title_display' => 'invisible',
'#empty_option' => $this
->t('- None -'),
'#options' => $entity_types,
'#default_value' => $this
->getSetting('entity-type'),
];
$form['submitted']['container']['entity-id'] = [
'#type' => 'number',
'#title' => $this
->t('Entity id'),
'#title_display' => 'invisible',
'#default_value' => $this
->getSetting('entity-id'),
'#min' => 1,
'#size' => 10,
'#states' => [
'invisible' => [
':input[name="entity-type"]' => [
'value' => '',
],
],
],
];
}
$form['num'] = [
'#type' => 'number',
'#title' => $this
->t('Number of submissions?'),
'#min' => 1,
'#required' => TRUE,
'#default_value' => $this
->getSetting('num'),
];
$form['kill'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Delete existing submissions in specified webform before generating new submissions'),
'#default_value' => $this
->getSetting('kill'),
];
$form['#validate'] = [
[
$this,
'validateForm',
],
];
return $form;
}