function activity_comments_form in Activity 7
Same name and namespace in other branches
- 6.2 activity_comments/activity_comments.module \activity_comments_form()
Add comment form.
1 string reference to 'activity_comments_form'
- activity_comments_handler_field_comments::render in activity_comments/
views/ activity_comments.views.inc - Render the field.
File
- activity_comments/
activity_comments.module, line 82 - Provides comment handling for activity messages
Code
function activity_comments_form($form, $form_state, $aid, $limit, $direction) {
// This could overrided the #attached elements already in the form, consider
// doing $form['attached']['css'][] = drupal_get_path(....)
$form['#attached'] = array(
'css' => array(
drupal_get_path('module', 'activity_comments') . '/activity_comments.css',
),
'js' => array(
drupal_get_path('module', 'activity_comments') . '/activity_comments.js',
),
);
$form['activity_form_items'] = array(
'#access' => user_access('activity post comments'),
'#prefix' => '<div class="container-inline activity-comment-add clearfix">',
'#suffix' => '</div>',
);
$form['activity_form_items']['activity_comment'] = array(
'#type' => 'textarea',
'#rows' => 2,
'#resizable' => FALSE,
'#attributes' => array(
'class' => array(
'activity-comment-text',
),
),
'#default_value' => t('Write a Comment'),
);
$form['aid'] = array(
'#type' => 'value',
'#value' => $aid,
);
$form['direction'] = array(
'#type' => 'value',
'#value' => $direction,
);
$form['activity_form_items']['activity_save_comment'] = array(
'#type' => 'submit',
'#value' => t('Add'),
'#ajax' => array(
'callback' => 'activity_comments_insert_ajax_callback',
'wrapper' => 'activity-comments-' . $aid,
'method' => 'replace',
'effect' => 'fade',
'keypress' => TRUE,
),
'#id' => 'activity-comment-save-comment-' . $aid,
);
// fetch all the comments for this
$query = db_select('activity_comments', 'ac')
->fields('ac', array(
'cid',
'comment',
'timestamp',
'uid',
))
->condition('ac.aid', $aid)
->fields('u', array(
'name',
))
->orderBy('ac.timestamp', $direction);
$query
->join('users', 'u', 'ac.uid = u.uid');
$items = $query
->execute()
->fetchAll();
// put all the comments into a markup for the form
$form['comments'] = array(
'#markup' => theme('activity_comments_comments', array(
'aid' => $aid,
'comments' => $items,
'limit' => $limit,
)),
'#weight' => -10,
);
// show all
$form['show_all'] = array(
'#prefix' => '<span class="activity-comment-show-all">',
'#markup' => '<a href="#">' . t('Show all !plural', array(
'!plural' => format_plural(count($items), '1 comment', '@count comments'),
)) . '</a>',
'#suffix' => '</span>',
'#weight' => -11,
'#access' => count($items) > $limit,
);
$form['#attributes'] = array(
'class' => 'activity_comment-comment-form',
);
// after build to add js
$form['#after_build'][] = 'activity_comments_add_js';
$form['#pre_render'][] = 'activity_comments_wrap';
return $form;
}