Search code examples
drupaldrupal-6drupal-modules

Drupal, how to Remove Login or comment link from webform pages?


I want to remove the Login or register to post comments text from the page where I created a webform; is there any suggestion as to how can i use hook_link_alter() with this?


Solution

  • This code resides in comment.module file under the theme_comment_post_forbidden() function.

    If you are using Drupal 7, you may use hook_node_view_alter or hook_entity_view_alter to modify the displayed content.

    function foo_node_view_alter (&$build) {
    
      if ($build['#node']->type == 'webform') {
        // remove login or register to post comments
        unset($build['links']['comment']['#links']['comment_forbidden']);
        // remove add comments
        unset($build['links']['comment']['#links']['comment_add']);
      }
    
    }
    

    In case you want to use hook_link_alter in Drupal 6, use this code in your custom module

    function comment_link_alter (&$links, $node) {
    
      if ($node->type == 'webform') {
        // remove register or login to post comments
        unset($links['comment_forbidden']);
        // remove add a comment
        unset($links['comment_add']);
      }
    
    }