function social_album_form_comment_form_alter in Open Social 10.1.x
Same name and namespace in other branches
- 10.3.x modules/social_features/social_album/social_album.module \social_album_form_comment_form_alter()
- 10.0.x modules/social_features/social_album/social_album.module \social_album_form_comment_form_alter()
- 10.2.x modules/social_features/social_album/social_album.module \social_album_form_comment_form_alter()
Implements hook_form_FORM_ID_alter().
File
- modules/
social_features/ social_album/ social_album.module, line 275 - The Social Album module.
Code
function social_album_form_comment_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$route_name = \Drupal::routeMatch()
->getRouteName();
if ($is_image_view = $route_name === 'social_album.image.view') {
/** @var \Drupal\comment\CommentInterface $comment */
$comment = $form_state
->getFormObject()
->getEntity();
$form['actions']['submit']['#attributes']['class'][] = 'post-index-' . $comment
->getCommentedEntityId();
if ($first =& drupal_static(__FUNCTION__, TRUE)) {
$first = FALSE;
}
else {
$form['actions']['submit']['#attributes']['class'][] = 'hide';
}
}
if (!(!\Drupal::moduleHandler()
->moduleExists('social_ajax_comments') || !\Drupal::moduleHandler()
->moduleExists('ajax_comments'))) {
return;
}
$allow = FALSE;
if ($is_image_view) {
$allow = TRUE;
}
elseif ($route_name === 'comment.reply' && \Drupal::routeMatch()
->getRawParameter('entity_type') === 'post') {
/** @var \Drupal\social_post\Entity\PostInterface $post */
$post = \Drupal::routeMatch()
->getParameter('entity');
if (!$post->field_album
->isEmpty()) {
/** @var \Drupal\node\NodeInterface $album */
$album = $post->field_album->entity;
if ($album
->toUrl()
->setAbsolute()
->toString() === \Drupal::request()->headers
->get('referer')) {
$allow = TRUE;
}
}
}
if ($allow) {
$form['actions']['submit']['#submit'][] = '_social_album_comment_submit';
}
}