public function WSServerForm::form in Web Service Data 8
Same name and namespace in other branches
- 2.0.x src/Form/WSServerForm.php \Drupal\wsdata\Form\WSServerForm::form()
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ WSServerForm.php, line 47
Class
- WSServerForm
- Class WSServerForm.
Namespace
Drupal\wsdata\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$wsserver_entity = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $wsserver_entity
->label(),
'#description' => $this
->t("Label for the Web Service Server."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $wsserver_entity
->id(),
'#machine_name' => [
'exists' => '\\Drupal\\wsdata\\Entity\\WSServer::load',
],
'#disabled' => !$wsserver_entity
->isNew(),
];
$endpoint = $wsserver_entity
->getEndpoint();
if (isset($wsserver_entity->state['endpoint'])) {
$this->messenger
->addWarning($this
->t('The endpoint is currently being overridden by the State API. The configured endpoint %configured and is being replaced with %endpoint.', [
'%configured' => $wsserver_entity->overrides['endpoint'],
'%endpoint' => $wsserver_entity
->getEndpoint(),
]));
$endpoint = $wsserver_entity->overrides['endpoint'];
}
$form['endpoint'] = [
'#type' => 'textfield',
'#title' => $this
->t('Endpoint'),
'#maxlength' => 1024,
'#default_value' => $endpoint,
'#description' => $this
->t('Endpoint for this webservice entity.'),
'#required' => TRUE,
];
$connector_definitions = $this->connectorManager
->getDefinitions();
$options = [];
foreach ($connector_definitions as $key => $connector) {
$options[$key] = $connector['label']
->render();
}
$form['wsconnector'] = [
'#type' => 'select',
'#title' => $this
->t('Connector'),
'#description' => $this
->t('Methods that data is retrieved.'),
'#options' => $options,
'#required' => TRUE,
'#default_value' => $wsserver_entity->wsconnector,
];
return $form;
}