public function WSDataService::wscallForm in Web Service Data 8
Same name and namespace in other branches
- 2.0.x src/WSDataService.php \Drupal\wsdata\WSDataService::wscallForm()
Generid WSCall setting form.
File
- src/
WSDataService.php, line 110
Class
- WSDataService
- Service for processing WSData requests.
Namespace
Drupal\wsdataCode
public function wscallForm($configurations = [], $wscall_option = NULL) {
$wscalls = $this->entity_type_manager
->getStorage('wscall')
->loadMultiple();
$options = [
'' => $this
->t('- Select -'),
];
foreach ($wscalls as $wscall) {
$options[$wscall
->id()] = $wscall
->label();
}
$element['wscall'] = [
'#type' => 'select',
'#title' => $this
->t('Web Service Call'),
'#options' => $options,
'#required' => TRUE,
'#ajax' => [
'callback' => 'Drupal\\wsdata\\WSDataService::wscallConfigurationsReplacements',
'wrapper' => 'wscall-replacement-tokens-wrapper',
],
'#default_value' => isset($configurations['wscall']) ? $configurations['wscall'] : '',
];
// Fetch the replacement tokens for this wscall.
$element['replacements'] = [
'#id' => 'wscall-replacement-tokens-wrapper',
'#type' => 'container',
];
// Based on the wscall create the replacements section of the wscall.
if (!empty($wscall_option)) {
foreach ($wscalls[$wscall_option]
->getReplacements() as $replacement) {
$element['replacements'][$replacement] = [
'#type' => 'textfield',
'#title' => $replacement,
'#default_value' => isset($configurations['replacements'][$replacement]) ? $configurations['replacements'][$replacement] : '',
];
}
}
$element['data'] = [
'#type' => 'textarea',
'#title' => $this
->t('Data'),
'#default_value' => isset($configurations['data']) ? $configurations['data'] : '',
];
$element['returnToken'] = [
'#type' => 'textfield',
'#title' => $this
->t('Token to select'),
'#description' => $this
->t('Seperate element names with a ":" to select nested elements.'),
'#default_value' => isset($configurations['returnToken']) ? $configurations['returnToken'] : '',
];
return $element;
}