1

I have added an image field to the comments.

This allows to my visitors to add images with a comment.

But I have annoying "help-block" for the image field in the form of adding a comment.

Drupal help-block for an image field in the Comment Form

How to gracefully to remove this stuff?

0

Drupal 7

I done it through the node_view_alter hook and my custom theme.

In the theme's template.php file I added the following function

function MyThemeName_node_view_alter(&$build) {
  if ($build['#node']->type !== 'My_Node_Type'){
    return;
  }

  // Your image field can not exist while saving comment.
  if(isset($build['comments']['comment_form']['My_Image_Field'])){
    // We can't use the unset function. Otherwise we can get something like this:
    // Notice: Undefined index: #file_upload_description in theme_file_widget_multiple() (row 863 file .../docs/modules/file/file.field.inc).
    $build['comments']['comment_form']['My_Image_Field']['und']['#file_upload_description'] = NULL;
  }
}

This removes the entire <p class="help-block">...</p> element.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.