Loading src/Form/MatomoAdminSettingsForm.php +14 −24 Original line number Diff line number Diff line Loading @@ -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'] = [ Loading Loading @@ -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(), Loading @@ -626,14 +620,12 @@ 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).', [ $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'); if (!empty($matomo_url_https)) { Loading @@ -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(), Loading @@ -654,15 +646,13 @@ 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).', [ $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(), ])); } } } // Verify that every path is prefixed with a slash, but don't check PHP // code snippets and do not check for slashes if no paths configured. Loading tests/src/Functional/MatomoPhpFilterTest.php +1 −4 Original line number Diff line number Diff line Loading @@ -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/'; Loading Loading @@ -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; Loading Loading
src/Form/MatomoAdminSettingsForm.php +14 −24 Original line number Diff line number Diff line Loading @@ -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'] = [ Loading Loading @@ -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(), Loading @@ -626,14 +620,12 @@ 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).', [ $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'); if (!empty($matomo_url_https)) { Loading @@ -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(), Loading @@ -654,15 +646,13 @@ 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).', [ $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(), ])); } } } // Verify that every path is prefixed with a slash, but don't check PHP // code snippets and do not check for slashes if no paths configured. Loading
tests/src/Functional/MatomoPhpFilterTest.php +1 −4 Original line number Diff line number Diff line Loading @@ -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/'; Loading Loading @@ -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; Loading