Skip to content

Commit 93ebe85

Browse files
committed
LOOP-1145: Fixed check to anonymous user in template
1 parent 940ef22 commit 93ebe85

File tree

5 files changed

+2
-57
lines changed

5 files changed

+2
-57
lines changed

web/profiles/custom/os2loop/modules/os2loop_post/os2loop_post.module

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,3 @@ function os2loop_post_help($route_name, RouteMatchInterface $route_match) {
3333
function os2loop_post_form_alter(array &$form, FormStateInterface $form_state, string $form_id) {
3434
Drupal::service(Helper::class)->alterForm($form, $form_state, $form_id);
3535
}
36-
37-
/**
38-
* Implements hook_os2loop_settings_is_granted().
39-
*
40-
* @see \Drupal\os2loop_post\Helper\Helper::isGranted()
41-
*/
42-
function os2loop_post_os2loop_settings_is_granted(string $attribute, $object = NULL) {
43-
return Drupal::service(Helper::class)->isGranted($attribute, $object);
44-
}

web/profiles/custom/os2loop/modules/os2loop_post/src/Helper/Helper.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Drupal\os2loop_post\Helper;
44

5-
use Drupal\comment\CommentInterface;
65
use Drupal\Core\Form\FormStateInterface;
76
use Drupal\os2loop_post\Form\SettingsForm;
87
use Drupal\os2loop_settings\Settings;
@@ -82,19 +81,4 @@ public function fieldAfterBuild(array $form_element, FormStateInterface $form_st
8281
return $form_element;
8382
}
8483

85-
/**
86-
* Implements hook_os2loop_settings_is_granted().
87-
*/
88-
public function isGranted(string $attribute, $object = NULL): bool {
89-
if ('view author' === $attribute) {
90-
if ($object instanceof CommentInterface) {
91-
if ($object->hasField('os2loop_comment_anonymous_author')) {
92-
return FALSE === (bool) $object->get('os2loop_comment_anonymous_author')->getString();
93-
}
94-
}
95-
}
96-
97-
return FALSE;
98-
}
99-
10084
}

web/profiles/custom/os2loop/modules/os2loop_question/os2loop_question.module

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,3 @@ function os2loop_question_help($route_name, RouteMatchInterface $route_match) {
3333
function os2loop_question_form_alter(array &$form, FormStateInterface $form_state, string $form_id) {
3434
Drupal::service(Helper::class)->alterForm($form, $form_state, $form_id);
3535
}
36-
37-
/**
38-
* Implements hook_os2loop_settings_is_granted().
39-
*
40-
* @see \Drupal\os2loop_question\Helper\Helper::isGranted()
41-
*/
42-
function os2loop_question_os2loop_settings_is_granted(string $attribute, $object = NULL) {
43-
return Drupal::service(Helper::class)->isGranted($attribute, $object);
44-
}

web/profiles/custom/os2loop/modules/os2loop_question/src/Helper/Helper.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Drupal\os2loop_question\Helper;
44

5-
use Drupal\comment\CommentInterface;
65
use Drupal\Core\Form\FormStateInterface;
7-
use Drupal\node\NodeInterface;
86
use Drupal\os2loop_question\Form\SettingsForm;
97
use Drupal\os2loop_settings\Settings;
108

@@ -139,24 +137,4 @@ public function fieldAfterBuild(array $form_element, FormStateInterface $form_st
139137
return $form_element;
140138
}
141139

142-
/**
143-
* Implements hook_os2loop_settings_is_granted().
144-
*/
145-
public function isGranted(string $attribute, $object = NULL): bool {
146-
if ('view author' === $attribute) {
147-
if ($object instanceof NodeInterface) {
148-
if ($object->hasField('os2loop_content_anonymous_author')) {
149-
return FALSE === (bool) $object->get('os2loop_content_anonymous_author')->getString();
150-
}
151-
}
152-
elseif ($object instanceof CommentInterface) {
153-
if ($object->hasField('os2loop_comment_anonymous_author')) {
154-
return FALSE === (bool) $object->get('os2loop_comment_anonymous_author')->getString();
155-
}
156-
}
157-
}
158-
159-
return FALSE;
160-
}
161-
162140
}

web/profiles/custom/os2loop/themes/os2loop_theme/templates/field/user-info.html.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
* - user: The user to display info about.
88
*/
99
#}
10-
{% set display_author = entity is empty or is_granted('view author', entity) %}
10+
{# Display author if not anonymous #}
11+
{% set display_author = not entity or not(entity.os2loop_content_anonymous_author.value or entity.os2loop_comment_anonymous_author.value) %}
1112
{% if display_author %}
1213

1314
<div class="user rounded-top">

0 commit comments

Comments
 (0)