Skip to content
Snippets Groups Projects
Commit bb235620 authored by dlevchik's avatar dlevchik Committed by Artem Sylchuk
Browse files

Issue #3386742 by dlevchik, artem_sylchuk: count the number of messages in thread

parent 697aeb8d
No related branches found
No related tags found
1 merge request!87Issue #3386742 by realgiucas, dlevchik: create view thread message count field
......@@ -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;
}
......
<?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));
}
}
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