You are here

public function HeartbeatActivityCommentsPlugin::createActivityAdditions in Heartbeat 7

createActivityAdditions().

1 call to HeartbeatActivityCommentsPlugin::createActivityAdditions()
HeartbeatActivityCommentsPlugin::loadAttachments in modules/heartbeat_comments/plugins/activitycomments.inc
loadAttachments().

File

modules/heartbeat_comments/plugins/activitycomments.inc, line 124
Defines activity comments.

Class

HeartbeatActivityCommentsPlugin
Class HeartbeatFlagAttachmentPlugin.

Code

public function createActivityAdditions($heartbeatActivity) {

  // Ease the settings retrieval.
  $settings = $heartbeatActivity->template->attachments['buttons']['settings'][$this->settings['plugin_name']];
  $this->orderStyle = $this->settings['heartbeat_comments_order'];
  $this->orderPosition = $this->settings['heartbeat_comments_position'];
  $this->commentDisplay = isset($this->settings['heartbeat_comments_show']) ? $this->settings['heartbeat_comments_show'] : TRUE;

  // Case if the comments are possible with nodes.
  if ($heartbeatActivity->nid > 0 && isset($heartbeatActivity->variables['node_type']) && module_exists('comment')) {
    $heartbeatActivity->message_nid_cache = $heartbeatActivity->nid;

    // Only nid & type is needed here (also for heartbeat_get_reactions)
    // so node_load is really over the top here.
    $this->parentNode = new stdClass();
    $this->parentNode->nid = $heartbeatActivity->nid;
    $this->parentNode->uid = $heartbeatActivity->variables['node_uid'];
    $this->parentNode->type = $heartbeatActivity->variables['node_type'];
    $this->parentNode->status = $heartbeatActivity->variables['node_status'];
    $this->isNodeComment = $settings['activitycomments_node'] && variable_get('comment_' . $this->parentNode->type, 2) > 0;
    $this->objectType = $this->parentNode->type;
  }

  // Case to check if the target node is set and is commentable and confiugred that way.
  if ($heartbeatActivity->nid_target > 0 && isset($heartbeatActivity->variables['node_target_type'])) {
    $this->parentNodeTarget = new stdClass();
    $this->parentNodeTarget->nid = $heartbeatActivity->nid_target;
    $this->parentNodeTarget->uid = $heartbeatActivity->variables['node_target_uid'];
    $this->parentNodeTarget->type = $heartbeatActivity->variables['node_target_type'];
    $this->parentNodeTarget->status = $heartbeatActivity->variables['node_target_status'];
  }
  if (!$this->isNodeComment) {

    // Reset the nid to 0 since we don't use it for node-type disabled comments.
    $heartbeatActivity->message_nid_cache = 0;
  }

  // Check access on the form submission.
  // Note that normal heartbeat comments will be used in case of node restrictions.
  if ($heartbeatActivity->message_nid_cache && $this->isNodeComment) {
    $this->canComment = user_access('post comments');
    $this->accessComment = user_access('access comments');
  }
  else {
    $this->canComment = user_access('add heartbeat comment');
    $this->accessComment = $this->canComment;
  }
}