From af08c37fdc863d8ec23f1d94e100851fa3875571 Mon Sep 17 00:00:00 2001
From: Lily Yan <l26yan@uwaterloo.ca>
Date: Mon, 27 Mar 2023 10:25:59 -0400
Subject: [PATCH] ISTWCMS-6260 Don't allow blank link text when <nolink> is
 used

---
 uw_cfg_common.module | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/uw_cfg_common.module b/uw_cfg_common.module
index d2329d3c..d9847a0e 100644
--- a/uw_cfg_common.module
+++ b/uw_cfg_common.module
@@ -1857,8 +1857,17 @@ function _uw_cfg_common_uw_link_validator($element, &$form_state, $form) {
     $form_state->setErrorByName($fieldname, t('The &lt;button&gt; value is not supported for this field.'));
   }
 
-  // Nolink is not allowed, with one exception.
-  if ($uri == '<nolink>' && $fieldname != 'field_uw_event_host][0][uri') {
-    $form_state->setErrorByName($fieldname, t('The &lt;nolink&gt; value is not supported for this field.'));
+  if ($uri == '<nolink>') {
+    // Don't allow blank link text when <nolink> is used.
+    if ($fieldname == 'field_uw_event_host][0][uri') {
+      $link_text = $form_state->getValue('field_uw_event_host')[0]['title'] ?? '';
+      if ($link_text == '') {
+        $form_state->setErrorByName('field_uw_event_host][0][title', t('You must provide link text when using &lt;nolink&gt; as the URL.'));
+      }
+    }
+    else {
+      // Nolink is not allowed, with one exception (event host field).
+      $form_state->setErrorByName($fieldname, t('The &lt;nolink&gt; value is not supported for this field.'));
+    }
   }
 }
-- 
GitLab