-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathComment.php
More file actions
50 lines (43 loc) · 1.61 KB
/
Comment.php
File metadata and controls
50 lines (43 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Drupal\wxt_bootstrap\Plugin\Preprocess;
use Drupal\bootstrap\Plugin\Preprocess\PreprocessBase;
use Drupal\bootstrap\Utility\Variables;
/**
* Implements hook_form_FORM_ID_alter().
*
* @ingroup plugins_form
*
* @BootstrapPreprocess("comment")
*/
class Comment extends PreprocessBase {
/**
* {@inheritdoc}
*/
public function preprocessVariables(Variables $variables) {
$variables['author'] = \Drupal::service('renderer')->render($elements);
$owner = $variables['comment']->getOwner();
if (empty($variables['author']) && $owner->id() === 0) {
$variables['author'] = $this->t('Anonymous');
}
if (empty($variables['author']) && $owner->isAuthenticated()) {
if ($owner->hasField('field_first_name') && $owner->hasField('field_last_name')) {
$first_name = $owner->get('field_first_name')->getString();
$last_name = $owner->get('field_last_name')->getString();
if (!empty($first_name) && !empty($last_name)) {
$variables['author'] = $first_name . ' ' . $last_name;
}
}
}
if (empty($variables['author'])) {
$variables['author'] = $variables['comment']->getAuthorName();
}
// Getting the node creation time stamp from the comment object.
$date = $variables['comment']->getCreatedTime();
// Adjust submitted display.
$variables['created'] = \Drupal::service('date.formatter')->format($date, 'wxt_standard');
$variables['submitted'] = $this->t('@username - <span class="comments-ago">@datetime </span>', [
'@username' => $variables['author'],
'@datetime' => $variables['created'],
]);
}
}