diff --git a/src/Form/ModuleConfigurationForm.php b/src/Form/ModuleConfigurationForm.php index e31adebd075baf7a675ec59e3fedbef6f73a39e9..ac9649ed720cb702dead0b6f7923ead32b16c50f 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.')); + } + } } }