Skip to content
Snippets Groups Projects
Commit 18cc78af authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2020395 by dawehner, oadaeh, mr.baileys, jibran, Andi-D: Convert [Who's...

Issue #2020395 by dawehner, oadaeh, mr.baileys, jibran, Andi-D: Convert [Who's new] block to a View.
parent 76114ccf
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
base_field: uid
base_table: users
core: 8.x
description: 'Shows a list of the newest user accounts on the site.'
status: '1'
display:
block_1:
display_plugin: block
id: block_1
display_title: 'Who''s new'
position: '1'
display_options:
display_description: 'A list of new users'
block_description: 'Who''s new'
block_category: 'User'
default:
display_plugin: default
id: default
display_title: Master
position: '1'
display_options:
access:
type: perm
options:
perm: 'access content'
perm: 'access user profiles'
cache:
type: none
options: { }
query:
type: views_query
options:
disable_sql_rewrite: '0'
distinct: '0'
slave: '0'
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: '0'
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: '1'
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: some
options:
items_per_page: '5'
offset: '0'
style:
type: html_list
row:
type: fields
fields:
name:
id: name
table: users
field: name
label: ''
alter:
alter_text: '0'
make_link: '0'
absolute: '0'
trim: '0'
word_boundary: '0'
ellipsis: '0'
strip_tags: '0'
html: '0'
hide_empty: '0'
empty_zero: '0'
link_to_user: '1'
overwrite_anonymous: '0'
relationship: none
group_type: group
admin_label: ''
exclude: '0'
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: '1'
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: '1'
empty: ''
hide_alter_empty: '1'
anonymous_text: ''
format_username: '1'
filters:
status:
value: '1'
table: users
field: status
id: status
expose:
operator: '0'
group: '1'
access:
id: access
table: users
field: access
relationship: none
group_type: group
admin_label: ''
operator: '>'
value:
min: ''
max: ''
value: '1970-01-01'
type: date
group: '1'
exposed: '0'
expose:
operator_id: '0'
label: ''
description: ''
use_operator: '0'
operator: ''
identifier: ''
required: '0'
remember: '0'
multiple: '0'
remember_roles:
authenticated: authenticated
is_grouped: '0'
group_info:
label: ''
description: ''
identifier: ''
optional: '1'
widget: select
multiple: '0'
remember: '0'
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: date
sorts:
created:
id: created
table: users
field: created
relationship: none
group_type: group
admin_label: ''
order: DESC
exposed: '0'
expose:
label: ''
granularity: second
plugin_id: date
title: 'Who''s new'
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
label: 'Who''s new'
module: views
id: who_s_new
tag: 'default'
uuid: 8b2c05e3-046b-447f-922b-43a832220667
langcode: en
<?php
/**
* @file
* Contains \Drupal\user\Plugin\Block\UserNewBlock.
*/
namespace Drupal\user\Plugin\Block;
use Drupal\block\BlockBase;
use Drupal\Core\Session\AccountInterface;
/**
* Provides a "Who's new" block.
*
* @Block(
* id = "user_new_block",
* admin_label = @Translation("Who's new"),
* category = @Translation("Lists (Views)")
* )
*/
class UserNewBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array(
'properties' => array(
'administrative' => TRUE
),
'whois_new_count' => 5
);
}
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
return $account->hasPermission('access content');
}
/**
* Overrides \Drupal\block\BlockBase::blockForm().
*/
public function blockForm($form, &$form_state) {
$form['user_block_whois_new_count'] = array(
'#type' => 'select',
'#title' => t('Number of users to display'),
'#default_value' => $this->configuration['whois_new_count'],
'#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)),
);
return $form;
}
/**
* Overrides \Drupal\block\BlockBase::blockSubmit().
*/
public function blockSubmit($form, &$form_state) {
$this->configuration['whois_new_count'] = $form_state['values']['user_block_whois_new_count'];
}
/**
* {@inheritdoc}
*/
public function build() {
// Retrieve a list of new users who have accessed the site successfully.
$uids = db_query_range('SELECT uid FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', 0, $this->configuration['whois_new_count'])->fetchCol();
$build = array(
'#theme' => 'item_list__user__new',
'#items' => array(),
);
foreach (user_load_multiple($uids) as $account) {
$username = array(
'#theme' => 'username',
'#account' => $account,
);
$build['#items'][] = drupal_render($username);
}
return $build;
}
}
......@@ -552,9 +552,6 @@ function user_preprocess_block(&$variables) {
case 'user_login_block':
$variables['attributes']['role'] = 'form';
break;
case 'user_new_block':
$variables['attributes']['role'] = 'complementary';
break;
}
}
}
......
......@@ -22,7 +22,7 @@ class DefaultViewsTest extends ViewTestBase {
*
* @var array
*/
public static $modules = array('views', 'node', 'search', 'comment', 'taxonomy', 'block');
public static $modules = array('views', 'node', 'search', 'comment', 'taxonomy', 'block', 'user');
/**
* An array of argument arrays to use for default views.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment