Skip to content
Snippets Groups Projects
Commit bee07b32 authored by Claudiu Cristea's avatar Claudiu Cristea
Browse files

Merge branch 'ISAICP-7690' into 'develop'

ISAICP: 7690: New information introduced on the Discussions tile.

See merge request digit/digit-joinup-dev!649
parents c5accb99 d6e9d6a0
No related branches found
No related tags found
No related merge requests found
Showing
with 130 additions and 16 deletions
......@@ -60,6 +60,7 @@ hidden:
flag_subscribe_discussions: true
invite_link: true
langcode: true
latest_update_time: true
links: true
og_audience: true
pinned_in: true
......
......@@ -145,6 +145,7 @@ hidden:
field_keywords: true
field_site_featured: true
langcode: true
latest_update_time: true
pinned_in: true
published_at: true
read_more: true
......
......@@ -69,6 +69,7 @@ hidden:
flag_subscribe_discussions: true
invite_link: true
langcode: true
latest_update_time: true
links: true
og_audience: true
pinned_in: true
......
......@@ -66,6 +66,7 @@ hidden:
flag_subscribe_discussions: true
invite_link: true
langcode: true
latest_update_time: true
links: true
og_audience: true
pinned_in: true
......
......@@ -90,6 +90,7 @@ hidden:
flag_subscribe_discussions: true
invite_link: true
langcode: true
latest_update_time: true
links: true
og_audience: true
pinned_in: true
......
......@@ -79,6 +79,7 @@ hidden:
flag_subscribe_discussions: true
invite_link: true
langcode: true
latest_update_time: true
links: true
og_audience: true
pinned_in: true
......
......@@ -16,7 +16,7 @@ Feature: Collection content
| modification date | 2017-11-30T11:11 |
| topic | HR |
And discussion content:
| title | body | state | collection | topic | creation date | changed |
| title | body | state | collection | topic | created | changed |
| Bigger than Egyptian Museum of Cairo? | <p><a href="#link">Link to the museum</a> web<strong>site</strong>.</p> | validated | Turin Egyptian Collection | Finance in EU, Supplier exchange, E-health, E-justice | 2017-11-11T11:11 | Wed, 25 Dec 2019 15:00:00 |
And document content:
| title | body | state | collection | creation date | changed | topic |
......
@api @group-d
Feature: Last Activity feature
As a user of the website
I want to be able to see last activity inside a tile.
Scenario: The discussion tile should show the last activity box.
Given the following collections:
| title | description | state |
| Development through bricolage | Bricolage 101. | validated |
| Carrots love tomatoes | Truth is out now. | validated |
And discussion content:
| title | state | collection | shared on | created | changed |
| Tools cabinet | validated | Development through bricolage | Carrots love tomatoes | 01-01-2023 | 01-01-2023 |
And users:
| Username | Roles | E-mail | First name | Family name |
| alicia__1997 | | AliciaPotter@example.com | Alicia | Potter |
When I go to the "Development through bricolage" collection
Then I should see the text "Discussions" in the "Navigation menu"
When I go to the discussions page of "Development through bricolage"
And I should see the "Tools cabinet" tile
And I should see the text "Last activity:" in the "Tools cabinet" tile
And I should see the text "01/01/2023" in the "Tools cabinet" tile
And the changed date of the "Tools cabinet" discussion is "01-02-2023 00:00"
When I go to the discussions page of "Development through bricolage"
Then I should see the text "Last activity:" in the "Tools cabinet" tile
And I should see the text "01/02/2023" in the "Tools cabinet" tile
Given I am an anonymous user
When I go to the discussions page of "Development through bricolage"
Then I should see the text "Last activity:" in the "Tools cabinet" tile
And I should see the text "01/02/2023" in the "Tools cabinet" tile
Given I am logged in as a moderator
When I go to the "Tools cabinet" discussion
And I enter "Mr scandal was doing something weird the other day." in the "Create comment" wysiwyg editor
And I press "Post comment"
And I go to the discussions page of "Development through bricolage"
Then I should see the text "Last activity:" in the "Tools cabinet" tile
And I should not see the text "01/02/2023" in the "Tools cabinet" tile
......@@ -11,6 +11,8 @@
use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\changed_fields\EntitySubject;
......@@ -19,6 +21,7 @@
use Drupal\joinup_discussion\Entity\DiscussionInterface;
use Drupal\joinup_discussion\Event\DiscussionDeleteEvent;
use Drupal\joinup_discussion\Event\DiscussionEvents;
use Drupal\joinup_discussion\LatestUpdateTimeFieldItemList;
use Drupal\node\NodeInterface;
/**
......@@ -27,7 +30,7 @@
* We use an observer to detect changes to the relevant fields of the discussion
* nodes. Then we call the observer update method to take action.
*/
function joinup_discussion_node_presave(NodeInterface $discussion) {
function joinup_discussion_node_presave(NodeInterface $discussion): void {
if ($discussion->bundle() === 'discussion') {
// Create a node subject object, add the observer and notify about changes.
$node_subject = new EntitySubject($discussion, 'default_field_comparator');
......@@ -36,10 +39,27 @@ function joinup_discussion_node_presave(NodeInterface $discussion) {
}
}
/**
* Implements hook_entity_bundle_field_info().
*/
function joinup_discussion_entity_bundle_field_info(EntityTypeInterface $entity_type, string $bundle) {
if ($entity_type->id() === 'node' && $bundle === 'discussion') {
$fields['latest_update_time'] = BaseFieldDefinition::create('datetime')
->setName('latest_update_time_field')
->setLabel(t('Last activity'))
->setComputed(TRUE)
->setClass(LatestUpdateTimeFieldItemList::class)
->setDisplayConfigurable('view', TRUE);
return $fields;
}
}
/**
* Implements hook_entity_extra_field_info().
*/
function joinup_discussion_entity_extra_field_info() {
function joinup_discussion_entity_extra_field_info(): array {
$fields = [];
$fields['node']['discussion']['display']['invite_link'] = [
......@@ -56,7 +76,7 @@ function joinup_discussion_entity_extra_field_info() {
*
* Adds an invite link to discussions.
*/
function joinup_discussion_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
function joinup_discussion_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, string $view_mode): void {
if (!$display->getComponent('invite_link')) {
return;
}
......@@ -109,7 +129,7 @@ function joinup_discussion_node_predelete(EntityInterface $entity): void {
/**
* Implements hook_entity_bundle_info_alter().
*/
function joinup_discussion_entity_bundle_info_alter(&$bundles) {
function joinup_discussion_entity_bundle_info_alter(array &$bundles): void {
if (!empty($bundles['node']['discussion'])) {
$bundles['node']['discussion']['class'] = Discussion::class;
}
......
......@@ -23,4 +23,15 @@ public function getLogoFieldName(): string {
return 'field_discussion_logo';
}
/**
* {@inheritdoc}
*/
public function getLatestUpdateTime(): int {
return (int) max(
$this->getCreatedTime(),
$this->getChangedTime(),
$this->get('field_replies')->last_comment_timestamp
);
}
}
......@@ -13,4 +13,12 @@
*/
interface DiscussionInterface extends CommunityContentInterface, ArchivableEntityInterface, LogoInterface {
/**
* Gets the discussion latest update time timestamp.
*
* @return int
* Latest update timestamp of the discussion.
*/
public function getLatestUpdateTime(): int;
}
<?php
declare(strict_types = 1);
namespace Drupal\joinup_discussion;
use Drupal\Core\Field\FieldItemList;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\TypedData\ComputedItemListTrait;
/**
* Defines a field item list class for the discussion's latest update time.
*/
class LatestUpdateTimeFieldItemList extends FieldItemList implements FieldItemListInterface {
use ComputedItemListTrait;
/**
* {@inheritdoc}
*/
protected function computeValue(): void {
$latest_update_time_formatted = (new \DateTime())->setTimestamp($this->getEntity()->getLatestUpdateTime())->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d\TH:i:s');
$this->list[0] = $this->createItem(0, $latest_update_time_formatted);
}
}
......@@ -71,15 +71,6 @@ function ventuno_preprocess_user__inline(array &$variables): void {
];
}
/**
* Implements hook_preprocess_username().
*/
function ventuno_preprocess_username(array &$variables): void {
// Variable name_full is set in joinup_user.module to make the full name
// visible on hover.
$variables['attributes']['title'] = $variables['name_full'];
}
/**
* Implements hook_preprocess_user__view_mode_tile().
*/
......@@ -127,3 +118,12 @@ function ventuno_preprocess_user__view_mode_tile(array &$variables): void {
}
}
}
/**
* Implements hook_preprocess_username().
*/
function ventuno_preprocess_username(array &$variables): void {
// Variable name_full is set in joinup_user.module to make the full name
// visible on hover.
$variables['attributes']['title'] = $variables['name_full'];
}
......@@ -110,10 +110,10 @@ function _ventuno_preprocess_tile(array &$variables, string $entity_type_id): vo
switch ($entity->bundle()) {
case 'discussion':
$variables['info']['icon'] = 'calendar-event';
if ($changed_time = $entity->getChangedTime()) {
if ($changed_time = $entity->getLatestUpdateTime()) {
$variables['info']['label'] = t('@label: @changed', [
'@label' => t('Last activity'),
'@changed' => $date_formatter->format($changed_time, 'custom', 'd/m/Y, h:s'),
'@changed' => $date_formatter->format($changed_time, 'custom', 'd/m/Y, h:i'),
]);
}
$node = $variables['elements']['#node'];
......
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