Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to show unread messages in PMM block? #34

Open
LubomirKurpel opened this issue Jul 16, 2020 · 3 comments
Open

How to show unread messages in PMM block? #34

LubomirKurpel opened this issue Jul 16, 2020 · 3 comments

Comments

@LubomirKurpel
Copy link

LubomirKurpel commented Jul 16, 2020

I found this in pmm-recent.html.twig. I think it is a prepare for actually having the number of unread messages in the block.

<span class="pmm-recent__message-count pmm-recent-count"></span>

But it looks like there is a twig variable missing inside. I am not that good in coding so I just pushed the value inside via javascript from official Private Message block rendered elsewhere but it would be very nice to have.

@LubomirKurpel
Copy link
Author

Oh i just found out how easy it was to insert the number inside, I just re-wrote it like this:

<span class="pmm-recent__message-count pmm-recent-count">{{ private_message_page_link }}</span>

now it works like a charm. Maybe it could be inside in the module? Minor change but it helps.

@LubomirKurpel
Copy link
Author

LubomirKurpel commented Jul 16, 2020

Okay so it looks like proper method should be this:

Add this line to template_preprocess_pmm_recent() function in .module file:

  $variables['strings'] = [
    'link' => t('Messages'),
    'more' => t('All Messages'),
    'loading' => t('Loading...'),
    **'new_messages' => \Drupal::service('private_message.service')->getUnreadThreadCount(),**
  ];

And then this to twig file:

<span class="pmm-recent__message-count pmm-recent-count">{{ strings.new_messages }}</span>

But now I am facing a twig caching problem, that new messages only come and are visible when cache is being cleared. Not good.

@UmitAltun
Copy link

I found such a solution for the cache problem I hope it works

https://www.drupal.org/project/blocache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants