Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
private_message
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
private_message
Commits
bb235620
Commit
bb235620
authored
1 year ago
by
dlevchik
Committed by
Artem Sylchuk
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3386742
by dlevchik, artem_sylchuk: count the number of messages in thread
parent
697aeb8d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!87
Issue #3386742 by realgiucas, dlevchik: create view thread message count field
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
private_message.module
+10
-0
10 additions, 0 deletions
private_message.module
src/Plugin/views/field/PrivateMessageThreadMessagesCount.php
+73
-0
73 additions, 0 deletions
src/Plugin/views/field/PrivateMessageThreadMessagesCount.php
with
83 additions
and
0 deletions
private_message.module
+
10
−
0
View file @
bb235620
...
...
@@ -50,6 +50,16 @@ function private_message_views_data() {
],
];
$data
[
'private_message_threads'
][
'all_messages_number'
]
=
[
'title'
=>
t
(
'All messages number'
),
'group'
=>
t
(
'Private Message Thread'
),
'field'
=>
[
'title'
=>
t
(
'All messages number'
),
'help'
=>
t
(
'Outputs simple messages count.'
),
'id'
=>
'private_message_thread_all_messages_number'
,
],
];
return
$data
;
}
...
...
This diff is collapsed.
Click to expand it.
src/Plugin/views/field/PrivateMessageThreadMessagesCount.php
0 → 100644
+
73
−
0
View file @
bb235620
<?php
namespace
Drupal\private_message\Plugin\views\field
;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\views\Plugin\views\field\FieldPluginBase
;
use
Drupal\views\ResultRow
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Outputs thread messages count.
*
* @ingroup views_field_handlers
*
* @ViewsField("private_message_thread_all_messages_number")
*/
class
PrivateMessageThreadMessagesCount
extends
FieldPluginBase
{
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected
$currentUser
;
/**
* Constructs a PrivateMessageThreadMessagesCount object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param AccountInterface $current_user
* The current user.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
AccountInterface
$current_user
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
currentUser
=
$current_user
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
return
new
static
(
$configuration
,
$plugin_id
,
$plugin_definition
,
$container
->
get
(
'current_user'
)
);
}
/**
* @{inheritdoc}
*/
public
function
query
()
{
// Leave empty to avoid a query on this field.
}
/**
* @{inheritdoc}
*/
public
function
render
(
ResultRow
$values
)
{
/** @var \Drupal\private_message\Entity\PrivateMessageThread $thread */
$thread
=
$this
->
getEntity
(
$values
);
return
count
(
$thread
->
filterUserDeletedMessages
(
$this
->
currentUser
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment