Elgg  Version 4.3
Social.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Menus;
4 
6 
13 class Social {
14 
22  public static function registerComments(\Elgg\Hook $hook) {
23  $entity = $hook->getEntityParam();
24  if (!$entity instanceof \ElggEntity || $entity instanceof \ElggComment) {
25  return;
26  }
27 
28  if (!$entity->hasCapability('commentable')) {
29  return;
30  }
31 
32  /* @var $return MenuItems */
33  $return = $hook->getValue();
34 
35  $comment_count = $entity->countComments();
36  $can_comment = $entity->canComment();
37  if ($can_comment || $comment_count) {
38  $text = $can_comment ? elgg_echo('comment:this') : elgg_echo('comments');
39 
40  $options = [
41  'name' => 'comment',
42  'icon' => 'comment',
43  'badge' => $comment_count ?: null,
44  'text' => $text,
45  'title' => $text,
46  'href' => $entity->getURL() . '#comments',
47  ];
48 
49  $item = $hook->getParam('item');
50  if ($item instanceof \ElggRiverItem && $can_comment) {
51  $options['href'] = "#comments-add-{$entity->guid}-{$item->id}";
52  $options['class'] = 'elgg-toggle';
53  }
54 
55  $return[] = \ElggMenuItem::factory($options);
56  }
57 
58  return $return;
59  }
60 }
if(!$items) $item
Definition: delete.php:13
static registerComments(\Elgg\Hook $hook)
Adds comment menu items to social menu.
Definition: Social.php:22
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
Register menu items to the social menu.
Definition: Social.php:13
$options
Elgg admin footer.
Definition: footer.php:6
static factory($options)
Create an ElggMenuItem from an associative array.
Models an event passed to hook handlers.
Definition: Hook.php:11
if(!empty($item->annotation_id)||!$object instanceof ElggEntity||$object instanceof ElggComment) if(!$object->hasCapability('commentable')) $comment_count
Definition: responses.php:34
$entity
Definition: reset.php:8
$text
Definition: button.php:32