Comments

vegantriathlete’s picture

Note: for D7 the hook is actually hook_permission() and it takes different arguments for the array returned. So, do you think I should create permission_example for D7 instead of creating perm_example?

vegantriathlete’s picture

StatusFileSize
new3.4 KB
new116 bytes

Here are the .info and .module for the D6 version. At least this way you can take a peek if you want and provide feedback.

I know that I still need to roll this properly as defined in create cron_example. I also know that I have not changed my editor configuration for the line endings as requested.

rfay’s picture

Please create patches. Thanks!

hutch’s picture

StatusFileSize
new3.91 KB

Here is a patch for perm_example, built in the same way as in #1289932

vegantriathlete’s picture

@hutch. Thanks for rolling the patch. I actually have a bit more I want to add to the module.

vegantriathlete’s picture

Status: Active » Needs review
StatusFileSize
new5.5 KB

I changed notepad++ to use Unix line endings. I added and committed the new module, and ran the diff against origin to get the attached patch file. However, I get warnings the LF will be replaced by CRLF. So, I still don't know if I've got things right. Also, coder_tough_love doesn't like what I'm doing the @see lines. Take a look and see if you are okay with it.

rfay’s picture

I guess the real question now to be answered is whether we need examples at this granularity.

The Page Example module already demonstrates hook_perm() pretty well. Why do you think we need an example dedicated to hook_perm()?

vegantriathlete’s picture

First off, I will admit that I hadn't looked at the page example. I've had a look at it now and it does provide some detail about hook_perm.

I know that I didn't think to look in the page_example module to see if it dealt with hook_perm. So, I wouldn't expect others to look at it to learn about permissions. But, maybe people do generally look through all the examples when they download the project. Somehow, I got it into my mind that the modules were named like hook_example, when in fact that isn't the case in general. On the contrary, it seems to be the case only for the modules I have been trying to add to the project and (sort of) for menu_example.

So, if you think that page_example is the most logical place to give details about hook_perm, then I think I should update page_example to include the things I put in this module.

Does that seem like a good course of action?

Also, what is your thought about my use of @see http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_perm/6 and [how] would you like to see it used in the other example modules?

Edit: I see that http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hoo... explicitly references page_example.module. So, I guess that answers my question about whether it's the most logical place.

Edit: According to Mile23 the appropriate way to add the hook references is NOT to use @see http://api.drupal.org/. . .. So, I think I've got my answer on that question.

rfay’s picture

To add hook references, you can just reference the hook, as in "implements hook_perm()" and it will show up as a link to the API for hook_perm.

I agree that page_example is an appropriate place for your energy on permissions - thanks for your flexibility.

But maybe this shows that we need an introduction document that explains to people what they may find inside examples. A reference of what hook is explained in what example...

vegantriathlete’s picture

Actually Mile23 said I should use @see hook_whatever() and doxygen will insert the appropriate link. The modules already [should] have Implements hook_whatever(). Many of them still say Implementation of hook_whatever(). But, I am already planning to get all that stuff cleaned up. Regardless, I am not seeing a link to the appropriate api included in the module itself. I don't think that's going to happen when I use @see either. My point is that people may not know about api.drupal.org and it would be good to point them to it explicitly in the module itself. Also, I must admit that I don't even know (for sure) where I'm supposed to go to read the doxygen comments. I thought that the doxygen comments are what create the documentation on api.drupal.org.

Are you suggesting that maybe we create index.module? I can take on that task as I'm going through this enhancement / cleanup process.

vegantriathlete’s picture

Title: Create perm_example » Give more detailed examples of hook_perm inside of page_example.module
Component: Other » Page Example
Status: Needs review » Active
rfay’s picture

To experiment and understand this, you can just look at existing stuff on api.drupal.org that is generated from examples. You'll note that everywhere it gives "implements anything()" that anything() gets turned into a link. You don't need the @see and it generally doesn't help, but might. The relatively trustworthy explanation of this stuff is at http://drupal.org/node/1354

vegantriathlete’s picture

I've got notepad++ set to use Unix EOL. But, this seems to trigger a warning in my Git Bash that says LF will be replaced by CRLF. So, I don't know how the patch is going to come across.

vegantriathlete’s picture

Status: Active » Needs review
StatusFileSize
new8.25 KB

This is the patch that was supposed to be attached above.

Status: Needs review » Needs work

The last submitted patch, more-hook-perm-1289930-13.patch, failed testing.

vegantriathlete’s picture

Status: Needs work » Needs review

Assuming you are happy with the above patch, I'll need to update the .test file. Agh! The patch failed anyway. Let me get that cleaned up.

I cleaned up to two exceptions. The fail results from the fact that I have changed some text that the .test is asserting. So, I have changed the .test file to assert the proper text. I have also added the other tests. I've got to install simpletest for D6 and check that everything is running okay.

But, what order are we supposed to do things now? The test file has changed and the module has changed.

vegantriathlete’s picture

Status: Needs review » Needs work

I've still got to get the .test and the .module cleaned up a bit more.

mile23’s picture

Regarding the @see stuff....

It's interesting because if you look at eg http://api.drupal.org/api/examples/action_example--action_example.module... you see that neither the text 'hook_action_info()' nor the @see directive link to the hook. And of course hook_action_info() exists in the api site. Maybe this is a problem with api.drupal.org, rather than the docblocks so much. Or perhaps API module doesn't like to link between projects.

...ahh, there it is, added by our own rfay: #990108: Links and search do not make sense and are not working across projects

rfay’s picture

I do stand corrected.

I see in action_example.module (source) that the hook is explained the way it ought to be.

I see in action_example_action_info() that *nothing* goes right with this. The see doesn't help, the link doesn't work, and the presentation as a function, which should have done the job, didn't.

hook_action_info() is in fact documented in system.api.php

However, note the simple reference to actions_do() in this link, which works fine as just a function statement.

I think something must be wrong somewhere.

rfay’s picture

Sorry, @Mile23 I didn't read your final resolution :-) Thanks for studying it.

vegantriathlete’s picture

What I'm really getting after with the @see (or whatever you think I should use) is that I want people who are looking at the code in the examples project to see the link to the api.drupal.org page. IMO, it's not about what api.drupal.org does with things (to create links). It's about the fact that I don't think we can assume that beginning developers even know about api.drupal.org. Hence my desire to explicitly point them to it in the documentation of the example modules.

So, for example [once I get all this straightened out], for the D7 version of the page_example.module in the spot where I am giving a more detailed explanation of hook_permissions() I would tell them to see http://api.drupal.org/api/drupal/modules--system--system.api.php/functio.... Similarly, in whichever .module and at whichever point we are illustrating a given hook we will point them to the page on api.drupal.org. We will choose just one place to do this; we won't do it with every use of the hook across all the modules.

deviantintegral’s picture

Assigned: vegantriathlete » Unassigned
Status: Needs work » Needs review
StatusFileSize
new8.72 KB

Here's a patch that:

  • d96ad8b Fix capitalization of Drupal.
  • 1a3e170 Use D6-style Implementation of.
  • f2033df Wrap at 80 characters.
  • 3042c56 Simplify quoted string.
  • ea5ee7c Add missing phpdoc comments.
  • 3e19068 Fix missing quotes around callback.
  • 7e2e9e0 Fix test text.

git diff to match the earlier patches, but I can reroll with better messages and git am if preferred.

The tests pass with this patch.

mile23’s picture

#22: 1289930.22-hook_perm.patch queued for re-testing.

mile23’s picture

Title: Give more detailed examples of hook_perm inside of page_example.module » Add tests for custom access pages
Status: Needs review » Needs work
Issue tags: +Novice

It'd be super-special-extra-credit great if there were tests for the new feature, but since this is D6, I'll commit #22 and leave the task open.

http://drupalcode.org/project/examples.git/commit/5e9abe7d021c9e04c455d7...

Thanks everyone for the work on this issue. As always, give a shout if you still have issues with it.

mile23’s picture

Issue summary: View changes
Status: Needs work » Fixed
Issue tags: -Novice

No one wrote tests. Closing this one.

It's end-of-life time for the 6.x-1.x branch of Examples. See #2642596: D6, D7 Roadmap for Examples

mile23’s picture

Title: Add tests for custom access pages » Give more detailed examples of hook_perm inside of page_example.module

Status: Fixed » Closed (fixed)

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