Commit 97b23807 authored by Florent Torregrosa's avatar Florent Torregrosa Committed by Florent Torregrosa
Browse files

Issue #3188589 by marco.aresu, Grimreaper, pfrenssen, davide.porrovecchio: Skip site ID error

parent a6951bc4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ function matomo_requirements($phase) {
    $config = \Drupal::config('matomo.settings');

    // Raise warning if Matomo user account has not been set yet.
    if (!preg_match('/^\d{1,}$/', $config->get('site_id') ?? '')) {
    if (empty($config->get('site_id') ?? '')) {
      $requirements['matomo_site_id'] = [
        'title' => t('Matomo module'),
        'description' => t('Matomo module has not been configured yet. Please configure its settings from the <a href=":url">Matomo settings page</a>.', [':url' => Url::fromRoute('matomo.admin_settings_form')->toString()]),
+1 −8
Original line number Diff line number Diff line
@@ -90,13 +90,10 @@ class MatomoAdminSettingsForm extends ConfigFormBase {
    $form['general']['matomo_site_id'] = [
      '#default_value' => $config->get('site_id'),
      '#description' => $this->t('The user account number is unique to the websites domain. Click the <strong>Settings</strong> link in your Matomo account, then the <strong>Websites</strong> tab and enter the appropriate site <strong>ID</strong> into this field.'),
      '#maxlength' => 20,
      '#required' => TRUE,
      '#size' => 15,
      '#title' => $this->t('Matomo site ID'),
      '#type' => 'number',
      '#min' => 0,
      '#step' => 1,
      '#type' => 'textfield',
    ];
    $form['general']['matomo_url_http'] = [
      '#default_value' => $config->get('url_http'),
@@ -616,10 +613,6 @@ class MatomoAdminSettingsForm extends ConfigFormBase {
    $form_state->setValue('matomo_visibility_user_role_roles', \array_filter($form_state->getValue('matomo_visibility_user_role_roles')));
    $form_state->setValue('matomo_trackmessages', \array_filter($form_state->getValue('matomo_trackmessages')));

    if (!\preg_match('/^\d+$/', $form_state->getValue('matomo_site_id'))) {
      $form_state->setErrorByName('matomo_site_id', $this->t('A valid Matomo site ID is an integer only.'));
    }

    $this->validateUrl('matomo_url_http', $form, $form_state);
    $this->validateUrl('matomo_url_https', $form, $form_state);

+0 −15
Original line number Diff line number Diff line
@@ -68,21 +68,6 @@ class MatomoBasicTest extends BrowserTestBase {
    $this->drupalGet('admin/config/system/matomo');
    $this->assertSession()->responseContains('Matomo site ID');

    // Check for account code validation.
    $edit['matomo_site_id'] = $this->randomMachineName(2);
    $edit['matomo_url_http'] = 'http://www.example.com/matomo/';
    $this->drupalGet('admin/config/system/matomo');
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->pageTextContains('Matomo site ID must be a number.');

    // Check that a validation error is shown for exponential number formats.
    // These are accepted by the core number field validation, but are not valid
    // as a Matomo site ID.
    $edit['matomo_site_id'] = '12.34e9';
    $this->drupalGet('admin/config/system/matomo');
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->pageTextContains('A valid Matomo site ID is an integer only.');

    // Verify that invalid URLs throw a form error.
    $edit = [];
    $edit['matomo_site_id'] = 1;