Skip to content
Snippets Groups Projects
Commit 43833c60 authored by Melissa Miller's avatar Melissa Miller
Browse files

url validation complete

parent 0901dc27
No related merge requests found
......@@ -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.'));
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment