Commit cfc84e3a authored by catch's avatar catch

Issue #1533020 by duellj: Convert comment.module entity classes to PSR-0.

parent e10c72ae
......@@ -5,6 +5,8 @@
* Admin page callbacks for the Comment module.
*/
use Drupal\comment\Comment;
/**
* Page callback: Presents an administrative comment listing.
*
......@@ -264,7 +266,7 @@ function comment_confirm_delete_page($cid) {
/**
* Form constructor for the confirmation form for comment deletion.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* The comment that is about to be deleted.
*
* @ingroup forms
......
......@@ -16,10 +16,10 @@
* This hook is invoked from comment_save() before the comment is saved to the
* database.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* The comment object.
*/
function hook_comment_presave(Comment $comment) {
function hook_comment_presave(Drupal\comment\Comment $comment) {
// Remove leading & trailing spaces from the comment subject.
$comment->subject = trim($comment->subject);
}
......@@ -27,10 +27,10 @@ function hook_comment_presave(Comment $comment) {
/**
* Respond to creation of a new comment.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* The comment object.
*/
function hook_comment_insert(Comment $comment) {
function hook_comment_insert(Drupal\comment\Comment $comment) {
// Reindex the node when comments are added.
search_touch_node($comment->nid);
}
......@@ -38,10 +38,10 @@ function hook_comment_insert(Comment $comment) {
/**
* Respond to updates to a comment.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* The comment object.
*/
function hook_comment_update(Comment $comment) {
function hook_comment_update(Drupal\comment\Comment $comment) {
// Reindex the node when comments are updated.
search_touch_node($comment->nid);
}
......@@ -52,7 +52,7 @@ function hook_comment_update(Comment $comment) {
* @param array $comments
* An array of comment objects indexed by cid.
*/
function hook_comment_load(Comment $comments) {
function hook_comment_load(Drupal\comment\Comment $comments) {
$result = db_query('SELECT cid, foo FROM {mytable} WHERE cid IN (:cids)', array(':cids' => array_keys($comments)));
foreach ($result as $record) {
$comments[$record->cid]->foo = $record->foo;
......@@ -62,7 +62,7 @@ function hook_comment_load(Comment $comments) {
/**
* Act on a comment that is being assembled before rendering.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* Passes in the comment the action is being performed on.
* @param $view_mode
* View mode, e.g. 'full', 'teaser'...
......@@ -71,7 +71,7 @@ function hook_comment_load(Comment $comments) {
*
* @see hook_entity_view()
*/
function hook_comment_view(Comment $comment, $view_mode, $langcode) {
function hook_comment_view(Drupal\comment\Comment $comment, $view_mode, $langcode) {
// how old is the comment
$comment->time_ago = time() - $comment->changed;
}
......@@ -108,20 +108,20 @@ function hook_comment_view_alter(&$build) {
/**
* Respond to a comment being published by a moderator.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* The comment the action is being performed on.
*/
function hook_comment_publish(Comment $comment) {
function hook_comment_publish(Drupal\comment\Comment $comment) {
drupal_set_message(t('Comment: @subject has been published', array('@subject' => $comment->subject)));
}
/**
* Respond to a comment being unpublished by a moderator.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* The comment the action is being performed on.
*/
function hook_comment_unpublish(Comment $comment) {
function hook_comment_unpublish(Drupal\comment\Comment $comment) {
drupal_set_message(t('Comment: @subject has been unpublished', array('@subject' => $comment->subject)));
}
......@@ -132,14 +132,14 @@ function hook_comment_unpublish(Comment $comment) {
* field_attach_delete() is called and before the comment is actually removed
* from the database.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* The comment object for the comment that is about to be deleted.
*
* @see hook_comment_delete()
* @see comment_delete_multiple()
* @see entity_delete_multiple()
*/
function hook_comment_predelete(Comment $comment) {
function hook_comment_predelete(Drupal\comment\Comment $comment) {
// Delete a record associated with the comment in a custom table.
db_delete('example_comment_table')
->condition('cid', $comment->cid)
......@@ -153,14 +153,14 @@ function hook_comment_predelete(Comment $comment) {
* field_attach_delete() has called and after the comment has been removed from
* the database.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* The comment object for the comment that has been deleted.
*
* @see hook_comment_predelete()
* @see comment_delete_multiple()
* @see entity_delete_multiple()
*/
function hook_comment_delete(Comment $comment) {
function hook_comment_delete(Drupal\comment\Comment $comment) {
drupal_set_message(t('Comment: @subject has been deleted', array('@subject' => $comment->subject)));
}
......
......@@ -6,7 +6,6 @@ core = 8.x
dependencies[] = node
dependencies[] = text
dependencies[] = entity
files[] = comment.entity.inc
files[] = comment.test
configure = admin/content/comment
stylesheets[all][] = comment.theme.css
......@@ -71,6 +71,8 @@
*/
const COMMENT_NODE_OPEN = 2;
use Drupal\comment\Comment;
/**
* Implements hook_help().
*/
......@@ -100,8 +102,8 @@ function comment_entity_info() {
'base table' => 'comment',
'uri callback' => 'comment_uri',
'fieldable' => TRUE,
'controller class' => 'CommentStorageController',
'entity class' => 'Comment',
'controller class' => 'Drupal\comment\CommentStorageController',
'entity class' => 'Drupal\comment\Comment',
'entity keys' => array(
'id' => 'cid',
'bundle' => 'node_type',
......@@ -934,7 +936,7 @@ function comment_prepare_thread(&$comments) {
/**
* Generates an array for rendering a comment.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* The comment object.
* @param Drupal\node\Node $node
* The node the comment is attached to.
......@@ -1004,7 +1006,7 @@ function comment_view(Comment $comment, Node $node, $view_mode = 'full', $langco
* The content built for the comment (field values, comments, file attachments
* or other comment components) will vary depending on the $view_mode parameter.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* A comment object.
* @param Drupal\node\Node $node
* The node the comment is attached to.
......@@ -1048,7 +1050,7 @@ function comment_build_content(Comment $comment, Node $node, $view_mode = 'full'
/**
* Adds reply, edit, delete, etc. links, depending on user permissions.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* The comment object.
* @param Drupal\node\Node $node
* The node the comment is attached to.
......@@ -1450,7 +1452,7 @@ function comment_user_predelete($account) {
* @param $op
* The operation that is to be performed on the comment. Only 'edit' is
* recognized now.
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* The comment object.
*
* @return
......@@ -1467,7 +1469,7 @@ function comment_access($op, Comment $comment) {
/**
* Accepts a submission of new or changed comment content.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* A comment object.
*/
function comment_save(Comment $comment) {
......@@ -1642,7 +1644,7 @@ function comment_get_display_page($cid, $node_type) {
/**
* Page callback: Displays the comment editing form.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* The comment object representing the comment to be edited.
*
* @see comment_menu()
......@@ -1879,7 +1881,7 @@ function comment_form_build_preview($form, &$form_state) {
/**
* Generates a comment preview.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
*
* @see comment_form_build_preview()
*/
......@@ -1981,7 +1983,7 @@ function comment_form_validate($form, &$form_state) {
/**
* Prepare a comment for submission.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
*
*/
function comment_submit(Comment $comment) {
......@@ -2324,7 +2326,7 @@ function comment_action_info() {
/**
* Publishes a comment.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* (optional) A comment object to publish.
* @param array $context
* Array with components:
......@@ -2351,7 +2353,7 @@ function comment_publish_action(Comment $comment = NULL, $context = array()) {
/**
* Unpublishes a comment.
*
* @param Comment|null $comment
* @param Drupal\comment\Comment|null $comment
* (optional) A comment object to unpublish.
* @param array $context
* Array with components:
......@@ -2378,7 +2380,7 @@ function comment_unpublish_action(Comment $comment = NULL, $context = array()) {
/**
* Unpublishes a comment if it contains certain keywords.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* Comment object to modify.
* @param array $context
* Array with components:
......@@ -2430,7 +2432,7 @@ function comment_unpublish_by_keyword_action_submit($form, $form_state) {
/**
* Saves a comment.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
*
* @ingroup actions
*/
......
......@@ -5,6 +5,8 @@
* Tests for the Comment module.
*/
use Drupal\comment\Comment;
class CommentHelperCase extends DrupalWebTestCase {
protected $profile = 'standard';
......@@ -96,7 +98,7 @@ class CommentHelperCase extends DrupalWebTestCase {
/**
* Checks current page for specified comment.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* The comment object.
* @param boolean $reply
* Boolean indicating whether the comment is a reply to another comment.
......@@ -123,7 +125,7 @@ class CommentHelperCase extends DrupalWebTestCase {
/**
* Deletes a comment.
*
* @param Comment $comment
* @param Drupal\comment\Comment $comment
* Comment to delete.
*/
function deleteComment(Comment $comment) {
......
<?php
/**
* @file
* Entity class for comments.
*/
namespace Drupal\comment;
use Entity;
/**
* Defines the comment entity class.
*/
class Comment extends Entity {
/**
* The comment ID.
*
* @var integer
*/
public $cid;
/**
* The parent comment ID if this is a reply to a comment.
*
* @var integer
*/
public $pid;
/**
* The comment language code.
*
* @var string
*/
public $langcode = LANGUAGE_NOT_SPECIFIED;
/**
* The comment title.
*
* @var string
*/
public $subject;
/**
* The comment author ID.
*
* @var integer
*/
public $uid = 0;
/**
* The comment author's name.
*
* For anonymous authors, this is the value as typed in the comment form.
*
* @var string
*/
public $name = '';
/**
* The comment author's e-mail address.
*
* For anonymous authors, this is the value as typed in the comment form.
*
* @var string
*/
public $mail;
/**
* The comment author's home page address.
*
* For anonymous authors, this is the value as typed in the comment form.
*
* @var string
*/
public $homepage;
/**
* Implements EntityInterface::id().
*/
public function id() {
return $this->cid;
}
/**
* Implements EntityInterface::bundle().
*/
public function bundle() {
return $this->node_type;
}
}
......@@ -2,91 +2,13 @@
/**
* @file
* Entity controller and class for comments.
* Entity controller class for comments.
*/
/**
* Defines the comment entity class.
*/
class Comment extends Entity {
/**
* The comment ID.
*
* @var integer
*/
public $cid;
/**
* The parent comment ID if this is a reply to a comment.
*
* @var integer
*/
public $pid;
/**
* The comment language code.
*
* @var string
*/
public $langcode = LANGUAGE_NOT_SPECIFIED;
/**
* The comment title.
*
* @var string
*/
public $subject;
/**
* The comment author ID.
*
* @var integer
*/
public $uid = 0;
namespace Drupal\comment;
/**
* The comment author's name.
*
* For anonymous authors, this is the value as typed in the comment form.
*
* @var string
*/
public $name = '';
/**
* The comment author's e-mail address.
*
* For anonymous authors, this is the value as typed in the comment form.
*
* @var string
*/
public $mail;
/**
* The comment author's home page address.
*
* For anonymous authors, this is the value as typed in the comment form.
*
* @var string
*/
public $homepage;
/**
* Implements EntityInterface::id().
*/
public function id() {
return $this->cid;
}
/**
* Implements EntityInterface::bundle().
*/
public function bundle() {
return $this->node_type;
}
}
use EntityDatabaseStorageController;
use EntityInterface;
/**
* Defines the controller class for comments.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment