function social_comment_form_comment_form_alter in Open Social 8
Same name and namespace in other branches
- 8.9 modules/social_features/social_comment/social_comment.module \social_comment_form_comment_form_alter()
- 8.2 modules/social_features/social_comment/social_comment.module \social_comment_form_comment_form_alter()
- 8.3 modules/social_features/social_comment/social_comment.module \social_comment_form_comment_form_alter()
- 8.4 modules/social_features/social_comment/social_comment.module \social_comment_form_comment_form_alter()
- 8.5 modules/social_features/social_comment/social_comment.module \social_comment_form_comment_form_alter()
- 8.6 modules/social_features/social_comment/social_comment.module \social_comment_form_comment_form_alter()
- 8.7 modules/social_features/social_comment/social_comment.module \social_comment_form_comment_form_alter()
- 8.8 modules/social_features/social_comment/social_comment.module \social_comment_form_comment_form_alter()
- 10.3.x modules/social_features/social_comment/social_comment.module \social_comment_form_comment_form_alter()
- 10.0.x modules/social_features/social_comment/social_comment.module \social_comment_form_comment_form_alter()
- 10.1.x modules/social_features/social_comment/social_comment.module \social_comment_form_comment_form_alter()
- 10.2.x modules/social_features/social_comment/social_comment.module \social_comment_form_comment_form_alter()
Implements hook_form_FORM_ID_alter().
Enhance the comment form.
File
- modules/
social_features/ social_comment/ social_comment.module, line 27 - The Social comment module.
Code
function social_comment_form_comment_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Change value of 'Save' button.
$form['actions']['submit']['#value'] = t('Comment', [], [
'context' => 'Comment Button',
]);
// Hide title of 'Comment' field.
if (!empty($form['field_comment_body']['widget'][0]['value']['#title_display'])) {
$form['field_comment_body']['widget'][0]['value']['#title_display'] = 'invisible';
}
// Validate replies to comments deeper than 1.
$form['#validate'][] = 'social_comment_form_reply_validate';
$route_name = \Drupal::routeMatch()
->getRouteName();
switch ($route_name) {
// Comment reply form.
case 'comment.reply':
$form['actions']['submit']['#attributes']['value'] = t('Reply');
$form['actions']['submit']['#value'] = t('Reply');
$form['field_comment_body']['widget'][0]['#placeholder'] = t('Add a reply');
break;
// Comment edit form.
case 'entity.comment.edit_form':
$form['actions']['submit']['#attributes']['value'] = t('Submit');
$form['actions']['submit']['#value'] = t('Submit');
break;
default:
// Redirect to the current url. We should not use this change for posts.
// See social_post_form_comment_post_comment_form_alter for posts.
if ($form_id !== 'comment_post_comment_form') {
$form['#action'] = \Drupal::request()
->getRequestUri();
}
break;
}
$form['#attached']['library'][] = 'social_post/keycode-submit';
}