public function HttpClientManagerConfigForm::buildForm in HTTP Client Manager 8.2
Same name and namespace in other branches
- 8 src/Form/HttpClientManagerConfigForm.php \Drupal\http_client_manager\Form\HttpClientManagerConfigForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ HttpClientManagerConfigForm.php, line 53
Class
- HttpClientManagerConfigForm
- Class HttpClientManagerConfigForm.
Namespace
Drupal\http_client_manager\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('http_client_manager.settings');
$form['enable_overriding_service_definitions'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable overriding of HTTP Services API definitions'),
'#description' => $this
->t('Check this option to enable overriding of HTTP Services API definitions.'),
'#default_value' => $config
->get('enable_overriding_service_definitions'),
];
$overrides = $config
->get('overrides');
$form['overrides'] = [
'#type' => 'table',
'#header' => [
'id' => $this
->t('ID'),
'title' => $this
->t('Title'),
'api_path' => $this
->t('API Path'),
'config' => $this
->t('Configurations'),
'commands' => $this
->t('Commands'),
],
];
$rows = [];
foreach ($this->httpServicesApi
->getServicesApi() as $service) {
$id = $service['id'];
$row = [
'id' => $service['id'],
'title' => [
'data' => [
'#type' => 'textfield',
'#title' => $this
->t('Override'),
'#name' => 'overrides[' . $id . '][title]',
'#value' => isset($overrides[$id]['title']) ? $overrides[$id]['title'] : NULL,
'#description' => $this
->t('Default value: @value', [
'@value' => isset($service['_original']['title']) ? $service['_original']['title'] : $service['title'],
]),
'#description_display' => 'after',
],
],
'api_path' => [
'data' => [
'#type' => 'textfield',
'#title' => $this
->t('Override'),
'#name' => 'overrides[' . $id . '][api_path]',
'#value' => isset($overrides[$id]['api_path']) ? $overrides[$id]['api_path'] : NULL,
'#description' => $this
->t('Default value: @value', [
'@value' => isset($service['_original']['api_path']) ? $service['_original']['api_path'] : $service['api_path'],
]),
'#description_display' => 'after',
],
],
'config' => [
'data' => [
'override' => [
'#title' => $this
->t('Override'),
'#type' => 'textarea',
'#name' => 'overrides[' . $id . '][config]',
'#value' => isset($overrides[$id]['config']) ? Yaml::encode($overrides[$id]['config']) : NULL,
'#rows' => 3,
'#placeholder' => $this
->t('Enter data in YAML format.'),
],
'default' => [
'#type' => 'details',
'#title' => $this
->t('Default value'),
'value' => [
'#markup' => '<pre>' . (!empty($service['_original']['config']) ? Yaml::encode($service['_original']['config']) : Yaml::encode($service['config'])) . '</pre>',
],
],
],
],
'commands' => [
'data' => [
'override' => [
'#title' => $this
->t('Override'),
'#type' => 'textarea',
'#name' => 'overrides[' . $id . '][commands]',
'#value' => isset($overrides[$id]['commands']) ? Yaml::encode($overrides[$id]['commands']) : NULL,
'#rows' => 3,
'#placeholder' => $this
->t('Enter data in YAML format.'),
'#element_validate' => [
[
$this,
'validateYaml',
],
],
],
'default' => [
'#type' => 'details',
'#title' => $this
->t('Default value'),
'value' => [
'#markup' => '<pre>' . (!empty($service['_original']['commands']) ? Yaml::encode($service['_original']['commands']) : NULL) . '</pre>',
],
],
],
],
];
$rows[] = $row;
}
$form['overrides']['#rows'] = $rows;
return parent::buildForm($form, $form_state);
}