Skip to content

Commit

Permalink
refactor(SHS-5954): Change validation to use Drupal core validateUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
codechefmarc committed Jan 13, 2025
1 parent 90e72b1 commit 48dcbc0
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Render\Element\Url;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -128,7 +129,7 @@ public function blockForm($form, FormStateInterface $form_state): array {
'link_url' => [
'#type' => 'textfield',
'#title' => $this->t('URL'),
'#description' => $this->t('Social Media Profile URL.'),
'#description' => $this->t('Social Media Profile URL. Must start with https:// or mailto:'),
'#default_value' => $link['link_url'],
'#element_validate' => [
[get_class($this), 'validateUrl'],
Expand Down Expand Up @@ -184,9 +185,7 @@ public static function validateUrl(array &$element, FormStateInterface $form_sta
}
}
else {
if (!filter_var($value, FILTER_VALIDATE_URL)) {
$form_state->setError($element, t('The URL must be a valid web address (e.g., https://www.stanford.edu) or a valid email address (e.g., mailto:example@stanford.edu).'));
}
URL::validateUrl($element, $form_state, $complete_form);
}
}

Expand Down

0 comments on commit 48dcbc0

Please sign in to comment.