Skip to content
Snippets Groups Projects
Commit 5f47789a authored by liuba's avatar liuba Committed by Florent Torregrosa
Browse files

Issue #3210239 by liuba, Grimreaper, C-Logemann: The url check on admin form...

Issue #3210239 by liuba, Grimreaper, C-Logemann: The url check on admin form validation is too retrictive
parent aa026cdd
No related branches found
No related tags found
1 merge request!23Issue #3210239: The url check on admin form validation is too retrictive
......@@ -115,11 +115,6 @@ class MatomoAdminSettingsForm extends ConfigFormBase {
'#title' => $this->t('Matomo HTTPS URL'),
'#type' => 'textfield',
];
// Required for automated form save testing only.
$form['general']['matomo_url_skiperror'] = [
'#type' => 'hidden',
'#default_value' => FALSE,
];
// Visibility settings.
$form['tracking_scope'] = [
......@@ -614,11 +609,10 @@ class MatomoAdminSettingsForm extends ConfigFormBase {
$form_state->setValueForElement($form['general']['matomo_url_http'], $url);
}
$url = $url . 'matomo.php';
$skip_error_check = $form_state->getValue('matomo_url_skiperror');
try {
$result = $this->httpClient->request('GET', $url);
if (!$skip_error_check && $result->getStatusCode() != 200) {
$form_state->setErrorByName('matomo_url_http', $this->t('The validation of "@url" failed with error "@error" (HTTP code @code).', [
if ($result->getStatusCode() != 200) {
$this->messenger()->addWarning($this->t('The validation of "@url" failed with error "@error" (HTTP code @code).', [
'@url' => UrlHelper::filterBadProtocol($url),
'@error' => $result->getReasonPhrase(),
'@code' => $result->getStatusCode(),
......@@ -626,13 +620,11 @@ class MatomoAdminSettingsForm extends ConfigFormBase {
}
}
catch (RequestException $exception) {
if (!$skip_error_check) {
$form_state->setErrorByName('matomo_url_http', $this->t('The validation of "@url" failed with an exception "@error" (HTTP code @code).', [
'@url' => UrlHelper::filterBadProtocol($url),
'@error' => $exception->getMessage(),
'@code' => $exception->getCode(),
]));
}
$this->messenger()->addWarning($this->t('The validation of "@url" failed with an exception "@error" (HTTP code @code).', [
'@url' => UrlHelper::filterBadProtocol($url),
'@error' => $exception->getMessage(),
'@code' => $exception->getCode(),
]));
}
$matomo_url_https = $form_state->getValue('matomo_url_https');
......@@ -645,8 +637,8 @@ class MatomoAdminSettingsForm extends ConfigFormBase {
$url = $url . 'matomo.php';
try {
$result = $this->httpClient->request('GET', $url);
if (!$skip_error_check && $result->getStatusCode() != 200) {
$form_state->setErrorByName('matomo_url_https', $this->t('The validation of "@url" failed with error "@error" (HTTP code @code).', [
if ($result->getStatusCode() != 200) {
$this->messenger()->addWarning($this->t('The validation of "@url" failed with error "@error" (HTTP code @code).', [
'@url' => UrlHelper::filterBadProtocol($url),
'@error' => $result->getReasonPhrase(),
'@code' => $result->getStatusCode(),
......@@ -654,13 +646,11 @@ class MatomoAdminSettingsForm extends ConfigFormBase {
}
}
catch (RequestException $exception) {
if (!$skip_error_check) {
$form_state->setErrorByName('matomo_url_https', $this->t('The validation of "@url" failed with an exception "@error" (HTTP code @code).', [
'@url' => UrlHelper::filterBadProtocol($url),
'@error' => $exception->getMessage(),
'@code' => $exception->getCode(),
]));
}
$this->messenger()->addWarning($this->t('The validation of "@url" failed with an exception "@error" (HTTP code @code).', [
'@url' => UrlHelper::filterBadProtocol($url),
'@error' => $exception->getMessage(),
'@code' => $exception->getCode(),
]));
}
}
......
......@@ -75,8 +75,7 @@ class MatomoPhpFilterTest extends BrowserTestBase {
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/config/system/matomo');
$page->find('css', '[name="matomo_url_skiperror"]')
->setValue(TRUE);
$edit = [];
$edit['matomo_site_id'] = $site_id;
$edit['matomo_url_http'] = 'http://www.example.com/matomo/';
......@@ -118,8 +117,6 @@ class MatomoPhpFilterTest extends BrowserTestBase {
$this->config('matomo.settings')->set('visibility.request_path_pages', '<?php return 0; ?>')->save();
$this->drupalGet('admin/config/system/matomo');
$page->find('css', '[name="matomo_url_skiperror"]')
->setValue(TRUE);
$edit = [];
$edit['matomo_site_id'] = $site_id;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment