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?
Comments
Comment #1
robertdouglass commentedI 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 =)
Comment #2
johnhanley commentedThat's good information. I wasn't able to find anything while searching so a code example would be helpful. Thanks!
Comment #3
webchickNodereview module does this like the following:
Comment #4
robertdouglass commentedWebchick, you rock!
Comment #5
johnhanley commentedWouldn'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.
Comment #6
johnhanley commentedAfter 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 (?)
Comment #7
robertdouglass commentedYou 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.
Comment #8
johnhanley commentedI'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.
Comment #9
robertdouglass commentedI 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.
Comment #10
johnhanley commentedSure, 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.
Comment #11
summit commentedHi,
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
Comment #12
oscarp commentedI 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
Comment #13
jyg commentedI 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
Comment #14
drupalicasso commentedI 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
Comment #15
summit commentedHi,
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:
The whole function now looks like this:
But it didn't work...what did I do wrong please?
EDIT: what works a little is:
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
Comment #16
go7 commentedHi 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.
Comment #17
kjpil commentedGood thread. How would you use this feature, where would you access this feature in Drupal 6 please?
Comment #18
summit commentedHi Bacteria Man,
Would this help?
Greetings,
Martijn
Comment #19
quicksketchI 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.
Comment #20
merlinofchaos commentedActually 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.
Comment #22
drupalok commentedsorry 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?
Comment #23
crea commented@drupalok your feature request is not very common and it would require a separate issue anyway. Closing this.