Skip to content
Snippets Groups Projects

Resolve #3471274 "Unstructured api host"

Files
3
@@ -40,20 +40,41 @@ class UnstructuredConfigForm extends ConfigFormBase {
$form['api_key'] = [
'#type' => 'key_select',
'#title' => $this->t('Unstructured API Key'),
'#description' => $this->t('The API Key if one is needed. If you are using api.unstructured.io, you need one.'),
'#description' => $this->t('The API Key if one is needed. If you are using api.unstructuredapp.io, you need one.'),
'#default_value' => $config->get('api_key'),
];
$form['host'] = [
'#type' => 'textfield',
'#title' => $this->t('Unstructured API Host'),
'#description' => $this->t('The host to use for the API. If you are using api.unstructured.io, you can leave this blank. If you are using an organization api from unstructured, you need the Base URL from the email unstructured sent.'),
'#default_value' => $config->get('host') ?? 'https://api.unstructured.io',
'#description' => $this->t('The host to use for the API. If you are using api.unstructuredapp.io, you can leave this blank. If you are using an organization api from unstructured, you need the Base URL from the email unstructured sent. You can find the API URL at <a href="@url" target="_blank">@url</a>. If you are using the <a href="@ddev">DDEV Unstructured add-on</a> your URL should be set to http://unstructured:8000.', [
'@url' => 'https://app.unstructured.io/keys',
'@ddev' => 'https://github.com/robertoperuzzo/ddev-unstructured',
]),
'#default_value' => $config->get('host') ?? 'https://api.unstructuredapp.io',
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$host = $form_state->getValue('host');
$urlParts = parse_url($host);
if (!empty($urlParts['path']) && $urlParts['path'] === '/') {
$error = $this->t('Do not enter a trailing slash.');
$form_state->setErrorByName('host', $error);
}
elseif (!empty($urlParts['path'])) {
$error = $this->t('Do not enter a path, enter only the host name like "https://example.com"');
$form_state->setErrorByName('host', $error);
}
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
Loading