Skip to content

Commit

Permalink
Changes for multiple delimiters
Browse files Browse the repository at this point in the history
  • Loading branch information
kedarkhaire committed Sep 7, 2023
1 parent 5e42934 commit 52881f6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
8 changes: 2 additions & 6 deletions src/Form/AppCallbackUrlSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <em>http://</em> or <em>https://</em>.'),
'#description' => $this->t('Regular expression that a Callback URL should match. Default is "^https?:\/\/.*$" that ensures callback url starts with either <em>http://</em> or <em>https://</em>. Avoid using delimiters.'),
'#required' => TRUE,
];
$form['callback_url']['pattern_error_message'] = [
Expand Down Expand Up @@ -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;
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/Plugin/Field/FieldWidget/AppCallbackUrlWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 52881f6

Please sign in to comment.