diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 27ff7c3..a3f57ce 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -216,7 +216,7 @@ function comment_field_extra_fields() { function comment_theme() { return array( 'comment_block' => array( - 'variables' => array(), + 'variables' => array('number' => NULL), ), 'comment_preview' => array( 'variables' => array('comment' => NULL), @@ -442,51 +442,6 @@ function comment_permission() { } /** - * Implements hook_block_info(). - */ -function comment_block_info() { - $blocks['recent']['info'] = t('Recent comments'); - $blocks['recent']['properties']['administrative'] = TRUE; - - return $blocks; -} - -/** - * Implements hook_block_configure(). - */ -function comment_block_configure($delta = '') { - $form['comment_block_count'] = array( - '#type' => 'select', - '#title' => t('Number of recent comments'), - '#default_value' => variable_get('comment_block_count', 10), - '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30)), - ); - - return $form; -} - -/** - * Implements hook_block_save(). - */ -function comment_block_save($delta = '', $edit = array()) { - variable_set('comment_block_count', (int) $edit['comment_block_count']); -} - -/** - * Implements hook_block_view(). - * - * Generates a block with the most recent comments. - */ -function comment_block_view($delta = '') { - if (user_access('access comments')) { - $block['subject'] = t('Recent comments'); - $block['content'] = theme('comment_block'); - - return $block; - } -} - -/** * Redirects comment links to the correct page depending on comment settings. * * Since comments are paged there is no way to guarantee which page a comment @@ -623,9 +578,9 @@ function comment_new_page_count($num_comments, $new_replies, Node $node) { * * @ingroup themeable */ -function theme_comment_block() { +function theme_comment_block($variables) { $items = array(); - $number = variable_get('comment_block_count', 10); + $number = $variables['number']; foreach (comment_get_recent($number) as $comment) { $items[] = l($comment->subject, 'comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)) . ' ' . t('@time ago', array('@time' => format_interval(REQUEST_TIME - $comment->changed))) . ''; } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/block/block/RecentBlock.php b/core/modules/comment/lib/Drupal/comment/Plugin/block/block/RecentBlock.php new file mode 100644 index 0000000..6f151fc --- /dev/null +++ b/core/modules/comment/lib/Drupal/comment/Plugin/block/block/RecentBlock.php @@ -0,0 +1,60 @@ + 10, + ); + } + + /** + * Implements BlockInterface::access(). + */ + public function access() { + return user_access('access comments'); + } + + /** + * Implements BlockInterface::configure(). + */ + public function configure($form, &$form_state) { + $form['block_count'] = array( + '#type' => 'select', + '#title' => t('Number of recent comments'), + '#default_value' => $this->configuration['block_count'], + '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30)), + ); + return $form; + } + + /** + * Implements BlockInterface::configureSubmit(). + */ + public function configureSubmit($form, &$form_state) { + $this->configuration['block_count'] = $form_state['values']['block_count']; + } + + /** + * Implements BlockInterface::build(); + */ + public function build() { + return array( + '#theme' => 'comment_block', + '#number' => $this->configuration['block_count'], + ); + } +}