diff --git a/src/Form/AppCallbackUrlSettingsForm.php b/src/Form/AppCallbackUrlSettingsForm.php index 345e7a10..17d89c08 100644 --- a/src/Form/AppCallbackUrlSettingsForm.php +++ b/src/Form/AppCallbackUrlSettingsForm.php @@ -61,7 +61,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'textfield', '#title' => $this->t('Pattern'), '#default_value' => $app_settings->get('callback_url_pattern'), - '#description' => $this->t('Regular expression that a Callback URL should match. Default is "^https?:\/\/.*$" that ensures callback url starts with either http:// or https://.'), + '#description' => $this->t('Regular expression that a Callback URL should match. Default is "^https?:\/\/.*$" that ensures callback url starts with either http:// or https://. Avoid using delimiters.'), '#required' => TRUE, ]; $form['callback_url']['pattern_error_message'] = [ @@ -94,12 +94,8 @@ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); $isRegExValid = FALSE; - $callback_url_pattern = $form_state->getValue(['callback_url', 'pattern']); - if (str_starts_with($callback_url_pattern, '/') && str_ends_with($callback_url_pattern, '/')) { - $callback_url_pattern = substr($callback_url_pattern, 1, -1); - } try { - if (@preg_match('/' . $callback_url_pattern . '/', '') !== FALSE) { + if (@preg_match('/' . $form_state->getValue(['callback_url', 'pattern']) . '/', '') !== FALSE) { $isRegExValid = TRUE; } } diff --git a/src/Plugin/Field/FieldWidget/AppCallbackUrlWidget.php b/src/Plugin/Field/FieldWidget/AppCallbackUrlWidget.php index c99bc39c..52d51a0e 100644 --- a/src/Plugin/Field/FieldWidget/AppCallbackUrlWidget.php +++ b/src/Plugin/Field/FieldWidget/AppCallbackUrlWidget.php @@ -85,11 +85,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // Fallback to the default configuration if field widget does // not have an override. $app_settings = \Drupal::config("apigee_edge.common_app_settings"); - $callback_url_pattern = $this->getSetting('callback_url_pattern') ?? $app_settings->get('callback_url_pattern'); - if (substr($callback_url_pattern, 0, 1) === '/' && substr($callback_url_pattern, -1) === '/') { - $callback_url_pattern = substr($callback_url_pattern, 1, -1); - } - $element['value']['#pattern'] = $callback_url_pattern; + $element['value']['#pattern'] = $this->getSetting('callback_url_pattern') ?? $app_settings->get('callback_url_pattern'); $element['value']['#attributes']['title'] = $this->getSetting('callback_url_pattern_error_message') ?? $app_settings->get('callback_url_pattern_error_message'); $element['value']['#placeholder'] = $this->getSetting('placeholder') ?? $app_settings->get('callback_url_placeholder'); $element['value']['#description'] = $this->getSetting('callback_url_description') ?? $app_settings->get('callback_url_description');