You are here

public function HeartbeatFlagAttachmentPlugin::loadAttachments in Heartbeat 7

loadAttachments().

Parameters

HeartbeatActivity $heartbeatActivity: The Heartbeat Activity Message object

String $name: The Flagname of the flag attached to the Message.

Overrides iHeartbeatPlugin::loadAttachments

File

modules/heartbeat_plugins/plugins/flagattachment.inc, line 54

Class

HeartbeatFlagAttachmentPlugin
Class HeartbeatFlagAttachmentPlugin.

Code

public function loadAttachments(HeartbeatActivity &$heartbeatActivity, $name = NULL) {

  // We need the flagname for flagmessages.
  if (!isset($name)) {
    return;
  }
  $pluginId = $this->settings['plugin_name'] . ":" . $name;
  $attachments = $heartbeatActivity->template->attachments;

  // Always load the flag (for content or buttons).
  $this->flag = flag_get_flag($name);

  // Load the count for this message if needed.
  if (isset($attachments['content']['enabled'][$pluginId])) {
    $counts = flag_get_counts('heartbeat_activity', $heartbeatActivity->uaid);
    $this->count = isset($counts[$name]) ? $counts[$name] : 0;
  }

  // Load the link for this message if needed.
  if (isset($attachments['buttons']['enabled'][$pluginId])) {
    $this->link = flag_create_link($name, $heartbeatActivity->uaid);
  }

  // Add the plugin to this message.
  if ($this->flag && _flag_content_enabled($this->flag, 'heartbeat_activity')) {
    $heartbeatActivity
      ->add_plugin($pluginId, $this);
  }
  else {
    $heartbeatActivity
      ->remove_plugin($pluginId);
  }
}