This is exactly the module I needed in trying to stay away from external analytics on a highly secure site.

However, I must be doing something wrong.

The Visitor block is showing markup instead of the rendered HTML.

For example, this is what I see on the page:

Total Visitors: <em class="placeholder">17</em>
Unique Visitors: <em class="placeholder">1</em>
Registered Users: <em class="placeholder">4</em>
Last Registered User: <a title="View user profile." href="/user/11" class="username">peter</a>
Published Nodes: <em class="placeholder">13</em>
Your IP: <em class="placeholder">[redacted]</em>
Since: <em class="placeholder">01/22/2024 - 09:33</em>

It's almost as if some of the HTML is escaped instead of being rendered.

Where would you look to find the issue?

I am using Bootstrap 5.3 (via Bootstrap5), as well as Drupal 10.2.2.

This particular block does not seem to have a twig template.

Any guidance would be greatly appreciated!

Thanks!

Issue fork visitors-3432630

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Noor Eldin Essam created an issue. See original summary.

nour eldin essam’s picture

Assigned: nour eldin essam » Unassigned
StatusFileSize
new2.62 KB
nour eldin essam’s picture

Issue summary: View changes
nour eldin essam’s picture

Issue summary: View changes
nour eldin essam’s picture

StatusFileSize
new2.62 KB
nour eldin essam’s picture

StatusFileSize
new2.62 KB
mahmoud barhouma’s picture

An error occurred after applying the patch
InvalidArgumentException: $string ("7057153") must be a string. in Drupal\Core\StringTranslation\TranslatableMarkup->__construct(

mahmoud barhouma’s picture

StatusFileSize
new2.75 KB
mahmoud barhouma’s picture

StatusFileSize
new2.75 KB
mahmoud barhouma’s picture

Status: Active » Needs work
g-brodiei’s picture

+++ b/src/Plugin/Block/VisitorsBlock.php
@@ -265,7 +265,7 @@ final class VisitorsBlock extends BlockBase implements ContainerFactoryPluginInt
+    $item = $this->t('Total Visitors:') .$count;

@@ -295,7 +295,7 @@ final class VisitorsBlock extends BlockBase implements ContainerFactoryPluginInt
+    $item = $this->t('Registered Users:') .$registered_users_count;

Thanks for the patch, works fine on 2.16, just some nit picks I see here, need to add space for concatenation.

immaculatexavier’s picture

Status: Needs work » Needs review
StatusFileSize
new2.76 KB
new729 bytes

As per #11 created patch by fixing the concatenation.
Kindly review

g-brodiei’s picture

Status: Needs review » Needs work
StatusFileSize
new95.29 KB
  /**
   * Display last registered user to visitors block.
   */
  protected function showLastRegisteredUser(): string {

    $last_user_uid = $this->database->select('users', 'u')
      ->fields('u', ['uid'])
      ->orderBy('uid', 'DESC')
      ->range(0, 1)
      ->execute()
      ->fetchField();

    $user = $this->entityTypeManager->getStorage('user')->load($last_user_uid);
    $username = [
      '#theme' => 'username',
      '#account' => $user,
    ];

    $item = $this->t('Last Registered User:') . $this->renderer->render($username);

    return $item;
  }

#12 applies cleanly to 2.x-dev, but the render array of 'Last registered user' still escapes html element, setting back to NW, thanks!

bluegeek9 made their first commit to this issue’s fork.

bluegeek9’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

bluegeek9’s picture

This issue was resolved. A new release, 8.x-2.17, will be made soon, May 31st.

This is an excellent opportunity to beta test the dev branch, and report any issues.

Contributors (5)

bluegeek9, roshni27, abhishek_gupta1, sarwan_verma, SandeepSingh199

Changelog

Issues: 32 issues resolved.

Changes since 8.x-2.16:

Bug

Feature

Task