Elgg  Version master
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\Event $event) {
23  $entity = $event->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 = $event->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 = $event->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
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
static factory(array $options)
Create an ElggMenuItem from an associative array.
Register menu items to the social menu.
Definition: Social.php:13
$options
Elgg admin footer.
Definition: footer.php:6
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
static registerComments(\Elgg\Event $event)
Adds comment menu items to social menu.
Definition: Social.php:22
Models an event passed to event handlers.
Definition: Event.php:11