Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EICNET-3000: Rephrase username in teaser for anonymous user so we hav… #2163

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,10 @@ function _preprocess_discussion_teaser(&$variables, $discussion_type, $node) {
];
}

// Privacy information, if current user is anonymous remove the author.
if (\Drupal::currentUser()->isAnonymous()) {
$teaser['author'] = NULL;
}

$variables['discussion_item'] = $teaser;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ function eic_community_preprocess_node__document(array &$variables) {
$variables['#attached']['library'][] = 'flag/flag.link_ajax';
}

// Privacy information, if current user is anonymous remove the author.
if (\Drupal::currentUser()->isAnonymous()) {
$teaser['author'] = NULL;
}

$variables['document_item'] = $teaser;
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ function eic_community_preprocess_node__event(array &$variables) {
}
}

// Privacy information, if current user is anonymous remove the author.
if (\Drupal::currentUser()->isAnonymous()) {
$teaser['author'] = NULL;
}

// Get the start date of the event.
$start_date = 0;
$end_date = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ function eic_community_preprocess_node__gallery(array &$variables) {
$teaser['flags'] = [];
}

// Privacy information, if current user is anonymous remove the author.
if (\Drupal::currentUser()->isAnonymous()) {
$teaser['author'] = NULL;
}

$teaser['images'] = $images;
$teaser['type'] = [
'label' => $node->type->entity->label(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ function _eic_community_preprocess_node_news_story(array &$variables) {
}

$variables['stats'] = $stats;

// Privacy information, if current user is anonymous remove the author.
if (\Drupal::currentUser()->isAnonymous()) {
$item['author'] = NULL;
}
}

$variables['story_item'] = $item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ function eic_community_preprocess_node__video(array &$variables) {
$teaser['flags'] = [];
}

// Privacy information, if current user is anonymous remove the author.
if (\Drupal::currentUser()->isAnonymous()) {
$teaser['author'] = NULL;
}

// If we have flags, attach the js library.
if (!empty($teaser['flags'])) {
$variables['#attached']['library'][] = 'flag/flag.link_ajax';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ function eic_community_preprocess_node__wiki_page(array &$variables) {
// Remove unwanted items.
$teaser['stats'] = [];

// Privacy information, if current user is anonymous remove the author.
if (\Drupal::currentUser()->isAnonymous()) {
$teaser['author'] = NULL;
}

$variables['story_item'] = $teaser;
break;

Expand Down
5 changes: 5 additions & 0 deletions lib/themes/eic_community/includes/preprocess/groups/group.inc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ function eic_community_preprocess_group__group(array &$variables) {
// @todo Get the real last activity.
$item['timestamp']['label'] = eic_community_get_teaser_time_display($group->get('changed')->value);

// Privacy information, if current user is anonymous remove the author.
if (\Drupal::currentUser()->isAnonymous()) {
$item['owner'] = NULL;
}

// Get group statistics.
$group_statistics = \Drupal::service('eic_group_statistics.helper')->loadGroupStatistics($group);
$item['stats'] = [
Expand Down
6 changes: 4 additions & 2 deletions lib/themes/eic_community/includes/preprocess/users/user.inc
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,18 @@ function _get_profile_image_array(EntityInterface $user, $relative_url = TRUE):
* @throws \Drupal\Core\TypedData\Exception\MissingDataException
*/
function eic_community_get_teaser_user_display(UserInterface $user, $picture_image_style = 'crop_36x36') {
$current_user = \Drupal::currentUser();

// Privacy information. If current user is anonymous set user to 'Someone'.
$author = [
'name' => $user->getDisplayName(),
'name' => $current_user->isAnonymous() ? t('Someone') : $user->getDisplayName(),
];

// We add the user profile page URL if the current user has access to it.
if ($user->toUrl()->access()) {
$author['path'] = $user->toUrl()->toString();
}

$current_user = \Drupal::currentUser();
if (!$user->get('field_media')->isEmpty() && !$current_user->isAnonymous()) {
$media_entity = $user->get('field_media')->entity;
if ($media_entity) {
Expand Down
5 changes: 5 additions & 0 deletions lib/themes/eic_community/includes/preprocess/views.inc
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ function _eic_community_preprocess_views__latest_news_and_stories__homepage(&$va
'stats' => $stats,
];

// Privacy information, if current user is anonymous remove the author.
if (\Drupal::currentUser()->isAnonymous()) {
$item['author'] = NULL;
}

if (!$node_translation->get('field_image')->isEmpty()) {
/** @var \Drupal\media\Entity\Media $media */
$media = \Drupal::service('entity.repository')->getTranslationFromContext($node_translation->get('field_image')->entity, $current_langcode);
Expand Down
Loading