Controller class for comments.
This extends the DrupalDefaultEntityController class, adding required special handling for comment objects.
| Name | Description |
|---|---|
| DrupalDefaultEntityController::$cache | Whether this entity type should use the static cache. |
| DrupalDefaultEntityController::$entityCache | Static cache of entities. |
| DrupalDefaultEntityController::$entityInfo | Array of information about the entity. |
| DrupalDefaultEntityController::$entityType | Entity type for this controller instance. |
| DrupalDefaultEntityController::$hookLoadArguments | Additional arguments to pass to hook_TYPE_load(). |
| DrupalDefaultEntityController::$idKey | Name of the entity's ID field in the entity database table. |
| DrupalDefaultEntityController::$revisionKey | Name of entity's revision database table field, if it supports revisions. |
| DrupalDefaultEntityController::$revisionTable | The table that stores revisions, if the entity supports revisions. |
drupal/
<?php
class CommentController extends DrupalDefaultEntityController {
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
$query = parent::buildQuery($ids, $conditions, $revision_id);
// Specify additional fields from the user and node tables.
$query->innerJoin('node', 'n', 'base.nid = n.nid');
$query->addField('n', 'type', 'node_type');
$query->innerJoin('users', 'u', 'base.uid = u.uid');
$query->addField('u', 'name', 'registered_name');
$query->fields('u', array('uid', 'signature', 'signature_format', 'picture'));
return $query;
}
protected function attachLoad(&$comments, $revision_id = FALSE) {
// Setup standard comment properties.
foreach ($comments as $key => $comment) {
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$comment->new = node_mark($comment->nid, $comment->changed);
$comment->node_type = 'comment_node_' . $comment->node_type;
$comments[$key] = $comment;
}
parent::attachLoad($comments, $revision_id);
}
}
?>