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  if ($entity->isDeleted()) {
33  return;
34  }
35 
36  /* @var $return MenuItems */
37  $return = $event->getValue();
38 
39  $comment_count = $entity->countComments();
40  $can_comment = $entity->canComment();
41  if ($can_comment || $comment_count) {
42  $text = $can_comment ? elgg_echo('comment:this') : elgg_echo('comments');
43 
44  $options = [
45  'name' => 'comment',
46  'icon' => 'comment',
47  'badge' => $comment_count ?: null,
48  'text' => $text,
49  'title' => $text,
50  'href' => $entity->getURL() . '#comments',
51  ];
52 
53  $item = $event->getParam('item');
54  if ($item instanceof \ElggRiverItem && $can_comment) {
55  $options['href'] = "#comments-add-{$entity->guid}-{$item->id}";
56  $options['class'] = 'elgg-toggle';
57  }
58 
59  $return[] = \ElggMenuItem::factory($options);
60  }
61 
62  return $return;
63  }
64 }
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
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
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:33
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