From 68559c59fa4a6b80d82ad7dca209da6de7434e84 Mon Sep 17 00:00:00 2001 From: Natkeeran Date: Tue, 22 Oct 2019 15:39:30 -0400 Subject: [PATCH] form validation for fedora url --- src/Form/IslandoraSettingsForm.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Form/IslandoraSettingsForm.php b/src/Form/IslandoraSettingsForm.php index c62871b5..3b56a11b 100644 --- a/src/Form/IslandoraSettingsForm.php +++ b/src/Form/IslandoraSettingsForm.php @@ -209,6 +209,27 @@ class IslandoraSettingsForm extends ConfigFormBase { ); } + // Validate Fedora URL. + $fedora_url = $form_state->getValue(self::FEDORA_URL); + $client = \Drupal::httpClient(); + $code = ""; + try { + $response = $client->get($fedora_url); + $code = $response->getStatusCode(); + } + catch (\Exception $e) { + $code = $e->getMessage(); + } + if ($code != "200") { + $form_state->setErrorByName( + self::FEDORA_URL, + $this->t( + 'Cannot connect to Fedora URL @url', + ['@url' => $fedora_url] + ) + ); + } + } /**