From 43833c60ec0adb7f1bb9ad934fc23e4f51f6f57c Mon Sep 17 00:00:00 2001
From: Melissa Miller <miller.2676@osu.edu>
Date: Tue, 18 Dec 2018 17:17:33 -0800
Subject: [PATCH] url validation complete

---
 src/Form/ModuleConfigurationForm.php | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/Form/ModuleConfigurationForm.php b/src/Form/ModuleConfigurationForm.php
index e31adeb..ac9649e 100644
--- a/src/Form/ModuleConfigurationForm.php
+++ b/src/Form/ModuleConfigurationForm.php
@@ -4,6 +4,7 @@ namespace Drupal\wcm8_siteinfo\Form;
 
 use Drupal\Core\Form\ConfigFormBase;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Component\Utility\UrlHelper;
 
 /**
  * Defines a form that configures module settings.
@@ -146,7 +147,7 @@ class ModuleConfigurationForm extends ConfigFormBase {
     $form['social'] = array(
       '#type' => 'details',
       '#title' => $this->t('Social Networking'),
-      '#description' => $this->t('Linked icons will be displayed in the site footer for each social media account url that you provide. Leave blank any fields that you do not want to be displayed.'),
+      '#description' => $this->t('Linked icons will be displayed in the site footer for each social media account URL that you provide. Leave blank any fields that you do not want to be displayed.'),
       '#group' => 'siteinfo',
     );
 
@@ -276,6 +277,15 @@ class ModuleConfigurationForm extends ConfigFormBase {
       }
     }
 
+    // url text fields
+    $urls = ['twitter', 'facebook', 'linkedin', 'googleplus', 'youtube', 'instagram', 'photos' ];
+    foreach ($urls as $url) {
+      $field_title = $form['social'][$url]['#title'];
+      $valid_url = UrlHelper::isValid($values[$url], TRUE);
+      if (!empty($values[$url]) && !$valid_url) {
+        $form_state->setErrorByName($url, $this->t('The ' . $field_title . ' link is not a valid URL.'));
+      }
+    }
   }
 
 }
-- 
GitLab