Suppress "comment" link in "create content" (node/add) page

Bacteria Man - August 22, 2007 - 18:31
Project:Node comments
Version:6.x-2.x-dev
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi,

Thanks for the time you've spent developing this module.

I just inherited a project which uses Node Comments and have the following dilemma. The client wants to prevent users from creating new comment nodes which aren't associated with another node type (i.e. stories, blog entries, etc.)

I therefore need to disable the link under "create content" and prevent users from accessing 'node/add/comment' directly. In other words the URI must include the 4th (originating node) segment.

I understand that this proposition is tricky at best because the "post comments" permission is tied to the "create content" output.

Can you think of a way to accomplish this?

#1

robertDouglass - August 23, 2007 - 06:53

I know there is an example in the wild of another module that successfully did this. I'll ask around which it was, and you should hop into #drupal or #drupal-dev and ask there as well. Then we can study the approach taken and see how it applies to nodecomment. The good news is that the ability to do this is a new feature in Drupal 6 =)

#2

Bacteria Man - August 23, 2007 - 15:57

That's good information. I wasn't able to find anything while searching so a code example would be helpful. Thanks!

#3

webchick - August 24, 2007 - 06:26

Nodereview module does this like the following:

<?php
function nodereview_menu() {
  ....
   
// Hide the normal node-add page, since we never want users to see it
   
$items[] = array(
     
'path' => 'node/add/nodereview',
     
'access' => FALSE,
    );
  ...
?>

#4

robertDouglass - August 24, 2007 - 10:43

Webchick, you rock!

#5

Bacteria Man - August 24, 2007 - 17:54

Wouldn't this make the node/add/comment page completely inaccessible?

I need a way to suppress the "create content" link and (ideally) prevent comment nodes without a parent node of some other type from being created separately.

This would be a whole lot easier if node_comment.module predefine its own node-type (i.e. "comment") and included a menu callback to a custom edit function. I could then simply remove the "title" element from the menu array, which would hide it from the "create content" page.

#6

Bacteria Man - August 24, 2007 - 22:46

After giving this matter some additional thought, the whole thing boils down to this.

If the URL does not include a 4th numeric segment (the parent node id) then reject the request. If it does, allow it. For example:

node/add/comment (reject)
node/add/comment/$arg (allow)

where $arg equals the parent node id.

I'd prefer a Drupal-based solution, but perhaps this config is best suited for Apache (?)

#7

robertDouglass - August 26, 2007 - 05:20

You can apply your logic and webchick's code to hook_menu of nodecomment. Depending on the conditions you spelled out, return the array from webchick (in $items) with access either TRUE or FALSE. Please roll a patch and submit here so that we can add this as a feature to the module.

#8

Bacteria Man - August 27, 2007 - 20:20

I'm happy to contribute, but I'm still not entirely sure what the proposed solution is.

I just need to hide the "create content" link, but still allow users to access node/add/comment.

#9

robertDouglass - August 28, 2007 - 06:16

I think the proposed solution goes somewhere along the lines of "am I on node/add? If so return FALSE for the access to node/add/comment. Otherwise return TRUE". This can all be done in nodecomment_menu in the !$may_cache section.

#10

Bacteria Man - August 28, 2007 - 13:58

Sure, I follow you. This should disallow the creation of random comment nodes.

However the missing piece of the puzzle and the most important part (at least for my needs) is how to hide the link from the "create content" page. In order for the patch to have real value, the code will need to decipher and suppress all links associated with node-type node_comments.

#11

Summit - February 21, 2008 - 09:11

Hi,
Any progress in this? I need to hide the comments on create content pages and for anonymous users it should only be possible to add comments to parent-nodes which are in the system.
Thanks you in advance for progress update!
Greetings,
Martijn

#12

oscarp - February 22, 2008 - 21:10

I am looking for a way to provide access control to the comments. This way the comments will be shown to users with a specific access or permissions level and not for others. Any ideas how can I do this?

Thanks

#13

jyg - March 14, 2008 - 23:55

I ran into this problem moments after I installed this module. After I finish the current project I am on, I am going to try to find some time to find a non-core module-based way to do this. But, for now, I hacked the drupal-5.7/modules/node/node.module file in what I believe is a completely unobtrusive manner. This php file controls, among many other things, the list of content types that get generated when you go to node/add ("Create content"). The loop that generates the list checks that the type has a create access permission for the current user and a _form function. To this boolean statement I added "and if this type is not a comment". Now the content type will not show up for anyone and the "Add new comment" will show up in content viewings and the create form is accessible.

As much as I hate hacking core functionality, this is very small. Keeping a good record of revisions will help if we ever need to upgrade.

Enjoy. I think this tiny hack makes this otherwise great module just right. I'm really glad I didn't have to write the whole thing :)


--- node.module (revision 6)
+++ node.module (working copy)
@@ -2208,7 +2208,7 @@
else {
// If no (valid) node type has been provided, display a node type overview.
foreach ($types as $type) {
- if (function_exists($type->module .'_form') && node_access('create', $type->type)) {
+ if (function_exists($type->module .'_form') && node_access('create', $type->type) && $type->type != "comment") {
$type_url_str = str_replace('_', '-', $type->type);
$title = t('Add a new @s.', array('@s' => $type->name));

jason

#14

drupalicasso - June 15, 2008 - 11:50

I am a noob and all I did to accompolish taht was to disable that particular menu item.
:)
Any myusers are no drupal experts, to know the direct links

#15

Summit - August 22, 2008 - 13:22
Version:5.x-1.0» 5.x-1.x-dev

Hi,

I didn;t want to hack core. I use drupal 5, 7 august 1.dev version.
I tried webchicks method, but it didn't work. Still in node/add the nodecomment type could be add.
The link itself is node/add/comment, so this is what I added in function nodecomment_menu:

function nodecomment_menu($may_cache) {
  $items = array();

    // Hide the normal node-add page, since we never want users to see it
    $items[] = array(
      'path' => 'node/add/comment',
      'access' => FALSE,
    );

The whole function now looks like this:

function nodecomment_menu($may_cache) {
  $items = array();

    // Hide the normal node-add page, since we never want users to see it
    $items[] = array(
      'path' => 'node/add/comment',
      'access' => FALSE,
    );

  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/settings/nodecomment',
      'title' => t('Comments'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('nodecomment_admin_settings'),
      'access' => user_access('administer comments'),
      'description' => t("Administer your site's comment settings."),
    );

  }
  else {
    if ((arg(0) == 'node') && is_numeric(arg(1)) && is_numeric(arg(2))) {
      $items[] = array(
        'path' => ('node/'. arg(1) .'/'. arg(2)),
        'title' => t('View'),
        'callback' => 'node_page',
        'type' => MENU_CALLBACK,
      );
    }
  }

  return $items;

But it didn't work...what did I do wrong please?

EDIT: what works a little is:

    // Hide the normal node-add page, since we never want users to see it
    $items[] = array(
      'path' => 'node/add/comment',
      'access' => user_access('administer comments'),
    );

But now I got the access denied page. What I would like is being able to tell the user this is not granted on this page...or better..get rid of the whole link node/add/comment on node/add page..

greetings,
Martijn

#16

go7 - September 16, 2008 - 00:05

Hi drupalicasso,

Thanks a lot for this simple and effective solution :). Glad that there are more newbies out there that have trouble following the posts, and still manage to find easy solutions.

#17

kjpil - September 19, 2008 - 18:02

Good thread. How would you use this feature, where would you access this feature in Drupal 6 please?

#18

Summit - October 13, 2008 - 09:32

Hi Bacteria Man,

Would this help?

if (arg(0) == "node" && arg(1) == "add" && arg(2) == "comment" && arg(3) == "") {
     $items[] = array(
        'path' => 'node/add/comment',
        'callback' => 'userreview_help',
        'callback arguments' => array('userreview_howto'),
        'title'    => t('How to Submit a Review'),
        'access'   => TRUE,
        'type'     => MENU_CALLBACK
      );
     }

Greetings,
Martijn

#19

quicksketch - June 6, 2009 - 02:19
Title:suppress "comment" link in "create content" page» Suppress "comment" link in "create content" (node/add) page
Version:5.x-1.x-dev» 6.x-2.x-dev
Category:support request» feature request

I think a reasonable way to handle this is to make a setting on the admin/content/node-type/x page for "Use this type exclusively for node comments", which we could then use to hook_menu_alter() the node/add/x item and disable access to it directly.

#20

merlinofchaos - June 10, 2009 - 05:53
Status:active» fixed

Actually disabling access is incorrect. Turning it into a MENU_CALLBACK and making sure it doesn't work without an argument works, however. This is now done in the 2.x branch.

#21

System Message - June 24, 2009 - 06:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#22

drupalok - August 19, 2009 - 10:26
Status:closed» active

sorry for opening this issue again... but it would be much better if i could choose (!) if i want to hide the creation link.

cause on the site i am building at the moment, there will be only 1 content type for users to post which will include all kinds of stuff...

--> and so the comment nodes and the initial posted nodes should be the same!

can you help me?

 
 

Drupal is a registered trademark of Dries Buytaert.