Updated: Comment #45

Problem/Motivation

The "Who's online" block is a custom list and should be a view since #1823450: [Meta] Convert core listings to Views

Proposed resolution

Convert it to a views block.

Remaining tasks

  1. Remove the current block.

  2. Add a views block.

  3. Fix broken tests.

User interface changes

The block config form. (see attached screenshots in comment #28)

API changes

None.

Follow up of #1823450: [Meta] Convert core listings to Views

Original report by @oadaeh

The title says it.

This is part of #1823450: [Meta] Convert core listings to Views

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

oadaeh’s picture

I don't want to hold anyone up who may also be working on this, but I have started this, and I will submit a patch later today.

oadaeh’s picture

Issue tags: +VDC

Forgot the tag.

Cameron Tod’s picture

Assigned: Unassigned » Cameron Tod
Cameron Tod’s picture

Assigned: Cameron Tod » Unassigned
Andi-D’s picture

Assigned: Unassigned » Andi-D

i work on it

Andi-D’s picture

Assigned: Andi-D » Unassigned
Status: Active » Needs review
FileSize
8.76 KB

I Created a new View.

views.view.user_online_block.yml

The View list a maximum off 10 Active User.

Following Fields are selected:

  • User: Name

Selected Filter Criteria

  • User: is Active: True
  • User: last Access: is greater or equal then -15 minutes

Header Field:

  • Custom Result Field
  • Currently is @total user online

No Results Behavior:

  • Custom Text Area
  • Currently are 0 users online

Also Removed the old UserOnlineBlock.php

Status: Needs review » Needs work

The last submitted patch, drupal-issue-2020399.patch, failed testing.

dawehner’s picture

There are currently two settings on the block:

oadaeh’s picture

It seems to me that the number is users to display is better as a Views setting, as a part of the Pager.

If i want to configure what and how that view is displaying data, I don't want to have to check (or even remember to check) in multiple places.

oadaeh’s picture

+++ b/core/modules/user/config/views.view.user_online_block.yml
@@ -0,0 +1,185 @@
+      access:
+        type: perm
+        options:
+          perm: 'access content'
+        perm: 'access user profiles'

This should not be here, because there is not similar functionality in the block that is being replaced.

+++ b/core/modules/user/config/views.view.user_online_block.yml
@@ -0,0 +1,185 @@
+      title: 'Who`s online'
...
+    display_title: 'User Online Block'
...
+      block_description: 'User Online Block'
...
+label: 'User Online Block'

These should be "Who's online" (or the YAML source of 'Who''s online').

+++ b/core/modules/user/config/views.view.user_online_block.yml
@@ -0,0 +1,185 @@
+          content: 'There is currently @total user online'

This doesn't properly account for more than 1 user. I also think this may need to be a handler.

+++ b/core/modules/user/config/views.view.user_online_block.yml
@@ -0,0 +1,185 @@
+    id: user_online_block
...
+id: user_online_block

These should end up becoming "who_s_online", with the changes above.

+++ b/core/modules/user/config/views.view.user_online_block.yml
@@ -0,0 +1,185 @@
+      sorts: {  }

There should be a descending sort on last access.

+++ b/core/modules/user/config/views.view.user_online_block.yml
@@ -0,0 +1,185 @@
+          content: 'There is currently @total user online'
...
+          content: "<p>There are currently 0 users online</p>\n"

The sentences should end w/a period.

+++ b/core/modules/user/config/views.view.user_online_block.yml
@@ -0,0 +1,185 @@
+          content: "<p>There are currently 0 users online</p>\n"
+          format: full_html

The text format should be Restricted HTML (except for #2031529: Fix JavaScript error when submitting a form that has a text_format selector set to a text format without associated text editor), or maybe it should be a Global: Unfiltered text field, instead.

I broke my test view testing this patch and discovering new bugs in Drupal 8, and I'm out of time for now, or I would have attached an updated patch. Maybe I will be able to do so later.

dawehner’s picture

We can now override the items per page, let's get this issue up to speed again.

dawehner’s picture

Status: Needs work » Needs review
FileSize
9 KB

This doesn't properly account for more than 1 user. I also think this may need to be a handler.

In an ideal world we could just use #1958538: Improve math expression engine

Rerolled the patch and fixed nearly all your points.

Status: Needs review » Needs work

The last submitted patch, vdc-2020399-12.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
10.34 KB

One problem here is that there is no count query executed so we have to fix that as well beside of the single/plural camps.

Status: Needs review » Needs work

The last submitted patch, vdc-2020399-14.patch, failed testing.

yanniboi’s picture

FileSize
646 bytes
10.35 KB
+++ b/core/modules/user/config/views.view.who_s_online.yml
@@ -0,0 +1,196 @@
+      footer: {  }
+      empty:
+        text_custom:
+          id: text_custom
+          table: views
+          field: text_custom
+          relationship: none
+          group_type: group

I assumed this was a typo because looking at the view this was showing up as 'broken/mission handler'.

I had a look at the code in views.view.user_admin_people.yml and it uses area_text_custom instead of text_custom. That seems to work.

+++ b/core/modules/user/config/views.view.who_s_online.yml
@@ -0,0 +1,196 @@
+      header:
+        result:
+          id: result
+          table: views
+          field: result
+          relationship: none
+          group_type: group
+          admin_label: ''
+          empty: '0'
+          content: 'There is currently @total users online.'
+          plugin_id: result

This code seems to be correct, but for some reason no kind of field placed in the header region of the view is being output by the block.

I don't know why that is.

yanniboi’s picture

Status: Needs work » Needs review

I'm pretty sure this patch is going to fail the tests, but I'll submit it anyway..

Status: Needs review » Needs work

The last submitted patch, vdc-2020399-16.patch, failed testing.

oadaeh’s picture

This may be a different issue, but I do not believe that @total is giving the correct answer. However, I'm having a hard time verifying it.

In core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php, $this->view->total_rows returns 0 every time, and count($this->view->result) only returns the number of records currently being displayed in the block. What we want is a count of the total number of users who are online, not the count of the total number of users displayed in the block.

I tried to track $total_rows down, but I lost the trail in core/modules/views/lib/Drupal/views/Plugin/views/pager/PagerPluginBase.php. It seems to me that executeCountQuery() is not being called, either at all or at the right time.

dawehner’s picture

The count of items are just count by default if a pager is existant, why otherwise you would need to count all the results.
What you though can do is $view->get_total_rows = TRUE ... something (probably the result area plugin, should set that), if @total is part of the output.

dawehner’s picture

oadaeh’s picture

The previous patch applies cleanly and works (except for the totaling, which is being handled in issue #2063461).

However, attached is an updated patch to address these three minor things I found:

@@ -0,0 +1,196 @@
+description: ''

The view is missing a description (added "Shows the user names of the most recently active users, and the total number of active users.").

@@ -0,0 +1,196 @@
+tag: ''

The view is missing a tag (added "default").

@@ -0,0 +1,196 @@
+          content: 'There is currently @total users online.'

This line has mixed pluralization. I changed it to match the no results content, and to get more of the likely possibilities (changed "is" to "are").

oadaeh’s picture

Status: Needs work » Needs review
FileSize
10.4 KB

Updated patch.

oadaeh’s picture

FileSize
4.97 KB

Since I was adding a screen shot to #2020395: Convert "Who's new" block to a View, I went ahead and created one for here.

views-whos-online-block.png

Status: Needs review » Needs work

The last submitted patch, views-whos-online-block-2020399-23.patch, failed testing.

jibran’s picture

Issue tags: +Needs screenshots

Please also share the screenshot of block configuration page.

yanniboi’s picture

Here are the before and after screenshots for block config:

yanniboi’s picture

block config before

block config after

yanniboi’s picture

FileSize
28.31 KB

I'ved debugged why the test fails for UserRoleUpgradePathTest.

It looks like in the DefaultPluginManager class when trying to create a block instance the following code is run:

<?php
  public function getDefinition($plugin_id) {
    // Fetch definitions if they're not loaded yet.
    if (!isset($this->definitions)) {
      $this->getDefinitions();
    }
    // Avoid using a ternary that would create a copy of the array.
    if (isset($this->definitions[$plugin_id])) {
      return $this->definitions[$plugin_id];
    }
    return array();
  }
?>

$this->getDefinitions() returns an array which is attached in the screenshot. The plugin_id that is being looked for is 'user_online_block' however, the plugin_id in the getDefinitions array is 'views_block:who_s_online-who_s_online_block'.

$definitions.png

This is as far as I've gotten...

yanniboi’s picture

dawehner’s picture

@yan
You don't often see a backtrace in an issue, cool stuff. We do replace the old plugin ('user_online_block') with the one based upon views,
so it seems totally valid that we have to change the test and replace this call

    $this->drupalGet('admin/structure/block/add/user_online_block/bartik');

with the one pointing to the views one.

yanniboi’s picture

Status: Needs work » Needs review
FileSize
907 bytes
11.28 KB

No problem!

Status: Needs review » Needs work

The last submitted patch, views-whos-online-block-2020399-32.patch, failed testing.

mr.baileys’s picture

Assigned: Unassigned » mr.baileys

Going to try and tackle this during the DrupalCon Prague Code Sprint.

mr.baileys’s picture

Status: Needs work » Needs review
FileSize
6.54 KB

The tests were failing since ViewsDefaultTest->testDefaultViews() was asserting on number of results returned > 0, and the test did not have any user logged in (so nobody "online"). I've expanded the ViewsDefaultTest->setUp() to log a user in, and the tests now pass.

Status: Needs review » Needs work

The last submitted patch, 2020399-35-views-whos-online.patch, failed testing.

mr.baileys’s picture

Status: Needs work » Needs review
FileSize
1.01 KB
11.99 KB

Forgot to include the new view's yml file in previous commit. Also made two additional changes:

  • Moved the block from the default "Views" category, to the "User" category.
  • Set the description of the block to "A list of users that are currently logged in.".

Status: Needs review » Needs work

The last submitted patch, 2020399-37-views-whos-online.patch, failed testing.

mr.baileys’s picture

The test is failing since the Views module is not enabled in the test database. It's not trivial to enable the Views module, since UpgradePathTestBase::setUp() does not enable additional modules.

yanniboi’s picture

Rather than enabling modules to get blocks, etc. we can just change the block that is being tested. All the test wants is a block that is available to check that the role visibility settings work, so I propose we use a different block (perhaps the 'powered by drupal' block).

mr.baileys’s picture

Status: Needs work » Needs review
FileSize
1.66 KB
12.94 KB

@yannoboi, good idea!

Patch attached that changes UserRoleUpgradePathTest to test role visibility during upgrade against the Powered By block.

dawehner’s picture

Rather than enabling modules to get blocks, etc. we can just change the block that is being tested. All the test wants is a block that is available to check that the role visibility settings work, so I propose we use a different block (perhaps the 'powered by drupal' block).

+2 for this idea!

BarisW’s picture

Patch works, looks good to me. If the test turns green, I'd say RTBC.

yanniboi’s picture

Status: Needs review » Reviewed & tested by the community

ITS GREEN :D

yanniboi’s picture

Issue summary: View changes

Added testing to the scope of the issue.

yanniboi’s picture

Issue summary: View changes

Updated issue summary.

yanniboi’s picture

Issue summary: View changes

updated issue summary

oadaeh’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
370 bytes
13.41 KB

I found a reference to the removed block in user.module.

yanniboi’s picture

Great catch @oadaeh!

+++ b/core/modules/user/user.module
@@ -562,9 +562,6 @@ function user_preprocess_block(&$variables) {
-      case 'user_online_block':
-        $variables['attributes']['role'] = 'complementary';
-        break;

Should we be setting the role attribute to 'complementary' on the new block?

yanniboi’s picture

Issue summary: View changes

removed double numbers

dawehner’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
FileSize
13.5 KB

Given that jbeach said that these are wrong anyway.

The patch was just a straight rerole.

Xano’s picture

47: vdc-2020399.patch queued for re-testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 47: vdc-2020399.patch, failed testing.

Xano’s picture

Status: Needs work » Needs review
FileSize
12.53 KB
yanniboi’s picture

Status: Needs review » Reviewed & tested by the community

If its just a straight re-roll then I think we can RTBC this.

yanniboi’s picture

Status: Reviewed & tested by the community » Needs review

Argh sorry. I still haven't gotten my head around the new issue queue.... I hadn'e noticed that the patch hadn't come back from testing yet...

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

@yanniboi

If the testbot fails it will be pushed back anyway, so it is kind of safe to set it RTBC

webchick’s picture

First, a simple one:

+++ b/core/modules/user/config/views.view.who_s_online.yml
@@ -0,0 +1,197 @@
+      block_category: 'User'

+++ /dev/null
@@ -1,110 +0,0 @@
- *   category = @Translation("Lists (Views)")

This was formerly in "Lists (Views)" category, and now shows up under 'User'. In #2085201: Use sensible block categories (rather than module-name categories) the UX team tried to deliberately simplify/English-ify the list of categories away from stock module names, so this needs to be switched back.

Next, a before/after comparison with the HEAD version of the block. I always do these without reading the issue first so I can come in "fresh," so apologies as always if I'm repeating stuff that was already said.

NOTE! In the past, I know I have burnt out the VDC team by doing these kinds of detailed UX reviews. My intention is NOT to burn anyone out! :( I am simply documenting what I see, which is my job as a patch reviewer/core committer. If it is unreasonable to fix some of these things (at least in this patch), then please push back and we can talk about it! Getting all of these blocks converted to Views would be a HUGE win not only for the VDC initiative, but also for D8, and I really, really want to see it happen! But I also need to give this the same scrutiny as I do other UX patches (ask anyone: I'm an equal-opportunity hard-ass :P) so we don't introduce regressions. I do this in order to make you guys look really effing good when new people encounter D8. :) Hugs, kisses, unicorns, ponies, <3 webchick. :D

Ok. With that out of the way....

HEAD's Who's Online block

Who's online block configuration page in HEAD
What happens when you save the block in HEAD

This patch's Who's Online block

Who's online block configuration page with this patch
What happens when you save the block in HEAD

Differences

- The most obvious one is that the block name is missing back on the block listing page. That's a commit blocker, unfortunately. There's no way for someone to determine what block that is short of hovering over the Configure link.
- That may be related to another obvious regression on the config form, where before we used a standard Name / Machine name pattern and now we just have the machine name sitting there glaring out at us menacingly. That's a pretty big regression, so I would love to see that fixed.
- Second, that field (once fixed) should really be at the top of the form, since that's the standard place for "namey" things.
- We also lost the ability to filter the block on the activity level of users from this form. While this is still possible to do by clicking into "Edit view" from contextual links and mucking about with the filters, that's definitely a LOT harder than it used to be. Do we have any provision for exposing this field like we do the count of records (which is also a views thing)?

Once the blocks are placed on the page, they look identical, so great work there. Needs work for the above though. Let's discuss.

webchick’s picture

Issue tags: +Usability

Probably also this.

webchick’s picture

+++ b/core/modules/user/user.module
@@ -571,9 +571,6 @@ function user_preprocess_block(&$variables) {
-      case 'user_online_block':
-        $variables['attributes']['role'] = 'complementary';
-        break;

Well, hold up now. What happened to this? This would cause an accessibility regression, no?

webchick’s picture

dawehner’s picture

NOTE! In the past, I know I have burnt out the VDC team by doing these kinds of detailed UX reviews. My intention is NOT to burn anyone out! :( I am simply documenting what I see, which is my job as a patch reviewer/core committer. If it is unreasonable to fix some of these things (at least in this patch), then please push back and we can talk about it! Getting all of these blocks converted to Views would be a HUGE win not only for the VDC initiative, but also for D8, and I really, really want to see it happen! But I also need to give this the same scrutiny as I do other UX patches (ask anyone: I'm an equal-opportunity hard-ass :P) so we don't introduce regressions. I do this in order to make you guys look really effing good when new people encounter D8. :) Hugs, kisses, unicorns, ponies, <3 webchick. :D

Thank you!!

This was formerly in "Lists (Views)" category, and now shows up under 'User'. In #2085201: Needs documentation: Use sensible block categories (rather than module-name categories) the UX team tried to deliberately simplify/English-ify the list of categories away from stock module names, so this needs to be switched back.

Right ... you seemed to have picked a bad example. You probably to know that I aggressively set these issues to RTBC, because no one will care anyway/otherwise, but I did tested them so the actual block rendering functionality works.

- Second, that field (once fixed) should really be at the top of the form, since that's the standard place for "namey" things.

Sure, well we just need yet another drupalcon to discuss things, another maybe skipped and finally one to fix it. This will be an endless story.

- We also lost the ability to filter the block on the activity level of users from this form. While this is still possible to do by clicking into "Edit view" from contextual links and mucking about with the filters, that's definitely a LOT harder than it used to be. Do we have any provision for exposing this field like we do the count of records (which is also a views thing)?

First note: There is one issue which provides an edit view link directly in the block interface (or at least allows to add one in the future).
This would certainly improve the usability a LOT here.

Second note: Let's shake our heads for a long time, let's make a long facepalm, and last but not least shout out loud. And again, and again ...
When we ran into the items per page problem like 9 months ago. There we decided that we don't need a generic override system.
Let me try to argue again why I think this filter is pointless anyway:

There are different people.

  • There is a hobbyist which just installs drupal, places some blocks and creates some content. That person
    gives a shit about when a user is considered to be online or not.
  • There is the hobbyist which builds some small websites for other
    people, like sport clubs, maybe some local NGOs. This is the region where drupal shines: you create content types, add some fields, create
    a view and you have immediately an event listing. No damn theming, no damn Yes, they maybe have logged in users, but they know what views is and at least can configure
    it to do simple things. This block already has the filter, so changing it is trivial for that person.
  • There is the professional site builder ... that person gives a shit about existing views and just start from scratch anyway

So if you still want to have that filter, feel free to mark just this issue as closed (works as designed), the other ones don't need that (and yes I used that word often) shit.

Well, hold up now. What happened to this? This would cause an accessibility regression, no?

See https://drupal.org/comment/8173469#comment-8173469 why we can remove it. I asked her to comment in one issue, even there are for sure multiple issues on which those problems apply.

- The most obvious one is that the block name is missing back on the block listing page. That's a commit blocker, unfortunately. There's no way for someone to determine what block that is short of hovering over the Configure link.

Yes, I know that this is kind of problem but I just ignored that in order to make progress on like 6 issues at a time. If we don't convert th

PS: Let's see whether I will translate "List (Views)" with just 'Views' in German to start a war just for fun.

My intention is NOT to burn anyone out!

Maybe you just manage to move people to more low level code. If you would ask me honest I would prefer to fix things instead of rerolling
all the patches all the time. The rerolling time can be invested in actually improving stuff.

webchick’s picture

Well, I'll just be honest and say that comment feels really hurtful. :( I genuinely am coming here from a position of respect for your work, and a genuine desire to help get it into core, and tried to make this extremely clear in my review. But now I'm just feeling utterly demoralized and attacked for simply doing my job. Thanks for your honesty, though, I guess...?

Probably best for another core maintainer to deal with these issues then. It doesn't make sense for me to continue to spend 3+ hours doing in-depth reviews on VDC conversion patches if this is the way those reviews are going to be received.

webchick’s picture

However, you did make the point (as non-constructively as possible) that changing the activity time filter most likely falls under the site builder persona vs. the content editor persona, so exposing a filter for it in the block configuration isn't necessary. So I withdraw that from my review.

webchick’s picture

And, it seems like #2135341: Views should provide a means to add arbitrary attributes (such as aria-* attributes) to a view's wrapping element will handle the concerns about the ARIA roles being lost, so site builders can put those back if they feel they're necessary. Which, in this case, it sounds like they're not, so we're fine there.

So that leaves fixing the category, fixing the block title on the block listing page, fixing the machine name field to be a normal name / machine name pairing, and moving the field to the top of the form (I've no idea why we need a DrupalCon to figure this out; check any form in core, it's the same).

And with that, I'm out. Still hope this makes it into core. But don't ping me about it again.

dawehner’s picture

Well, I'll just be honest and say that comment feels really hurtful. :( I genuinely am coming here from a position of respect for your work, and a genuine desire to help get it into core, and tried to make this extremely clear in my review. But now I'm just feeling utterly demoralized and attacked for simply doing my job. Thanks for your honesty, though, I guess...?

Damn, I am sorry. It is sadly so hard to express thoughts in a non native language, and not piss of you. Sorry! I did not intended it.

:( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :(
:( :( :( :( :( :( :( :( :( :( :( /me hugs :( :( :( :( :( :( :( :(
:( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :(

webchick’s picture

Status: Needs work » Fixed
Issue tags: +alpha target

dawehner and I subsequently hugged and made up on IRC. :) I'd also love to get all of these views conversions in in the next alpha, so tagging.

Now that #1957276: Let users set the block instance title for Views blocks in the Block UI is in, my main point of feedback was addressed, and #2151731: Views blocks' machine names do not fit the standard Drupal pattern will address the second. The only other thing was the View category was incorrect, but simply by removing the block_category line from the YAML file, that's fixed up to. So!

Committed and pushed to 8.x. YEAH!

dawehner’s picture

webchick++

Status: Fixed » Closed (fixed)

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