hook_captcha() documentation is lacking proper documentation and the API file has incorrect naming, too.

Todo:

  1. Rename captcha_api.txt to captcha.api.php
  2. Add $captcha_sid argument to the documenation and explain what it does. Not only explain that it exists and is an optional argument. It is not clear what it is made for, how it works and how unique it is.
CommentFileSizeAuthor
#65 2548049-65.patch763 bytesshubham.prakash
#59 document_all_arguments-2548049-59.patch815 bytesyogeshmpawar
#59 interdiff-2548049-55-59.txt524 bytesyogeshmpawar
#55 document_all_arguments-2548049-55.patch652 bytesyogeshmpawar
#43 document_all_arguments-2548049-43.patch13.9 KByogeshmpawar
#43 interdiff-2548049-40-43.txt9.5 KByogeshmpawar
#40 document_all_arguments-2548049-40.patch8.89 KByogeshmpawar
#38 document_all_arguments-2548049-38.patch8.49 KByogeshmpawar
#38 interdiff-2548049-27-38.txt674 bytesyogeshmpawar
#28 document_all_arguments-2548049-27.patch8.11 KByogeshmpawar
#27 interdiff-2548049-25-27.txt398 bytesyogeshmpawar
#27 document_all_arguments-2548049-27.patch8.11 KByogeshmpawar
#25 document_all_arguments-2548049-25.patch8 KByogeshmpawar
#17 captcha-2548049-17.patch4.96 KBchishah92
#13 captcha-2548049-10.patch13.77 KBDinesh18
#11 captcha-2548049-10.patch13.77 KBDinesh18
#4 captcha-2548049-file-ranamed-4.patch14.17 KBrashid_786
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hass created an issue. See original summary.

wundo’s picture

I slightly disagree about the steps that should be taken here, I'd suggest:

  1. Move captcha_api.txt to docs/
  2. Create a proper captcha.api.php
  3. Rename captcha_api.txt to api.md

  • wundo committed c42e15c on 8.x-1.x
    Issue #2548049: Moving captcha_api.txt to docs/
    
rashid_786’s picture

captcha_api.txt renamed as api.md

rashid_786’s picture

Status: Active » Needs review

  • elachlan committed 58a9843 on 8.x-1.x authored by rashid_786
    Issue #2548049 by rashid_786, wundo: Document all arguments to...

  • elachlan committed 3a0996a on 8.x-1.x authored by rashid_786
    Issue #2548049 by rashid_786, wundo: Document all arguments to...
elachlan’s picture

Status: Needs review » Needs work

Last step "Create a proper captcha.api.php"

hass’s picture

That is not correct. Hook_captcha has an undocumented 3rd argument and I need to know how this works.

Does drupal .htaccess block requests to .md files?

Dinesh18’s picture

Assigned: Unassigned » Dinesh18
Dinesh18’s picture

Assigned: Dinesh18 » Unassigned
Status: Needs work » Needs review
FileSize
13.77 KB

I have checked the core modules and we need to remove the docs folder. we need to add the file captcha.api.php inside the captcha module folder. Also, I don't think we need to add any .md files in this folder.
An optional additional argument $captcha_sid with the captcha session ID is available for more advanced challenges (e.g. the image CAPTCHA uses this argument, see image_captcha_captcha()) and it is used for every session. Strictly speaking, it is not necessary to send the CAPTCHA session id with the form, as the one time CAPTCHA token is enough. However, we still send it along, because it can help debugging problems on live sites with only access to the markup.

Status: Needs review » Needs work

The last submitted patch, 11: captcha-2548049-10.patch, failed testing.

Dinesh18’s picture

Status: Needs work » Needs review
FileSize
13.77 KB

Updated Patch.

hass’s picture

Status: Needs review » Needs work

This does not document the 3rd param of hook_captcha() what I mainly asked for.

naveenvalecha’s picture

Priority: Major » Normal
Issue tags: +Novice, +Needs reroll

Bumping to normal as its only related to documentation.

chishah92’s picture

Assigned: Unassigned » chishah92
chishah92’s picture

Status: Needs work » Needs review
FileSize
4.96 KB

Rerolled the patch

Status: Needs review » Needs work

The last submitted patch, 17: captcha-2548049-17.patch, failed testing.

hass’s picture

The 3rd param of the hook_captcha() is still not documented and the MAIN reason why I opened the case as I do not understand it at all.

andriyun’s picture

Issue tags: -Needs reroll
elachlan’s picture

Issue tags: +Needs reroll, +Release blocker
naveenvalecha’s picture

Issue tags: -Release blocker

Assuming documentation will not block the release.

naveenvalecha’s picture

Category: Bug report » Task

This issue need documentation changes.So it's more of a task rather than bug.

yogeshmpawar’s picture

Assigned: chishah92 » yogeshmpawar
yogeshmpawar’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
8 KB

Documented all arguments & fix the broken documentations.

Status: Needs review » Needs work

The last submitted patch, 25: document_all_arguments-2548049-25.patch, failed testing.

yogeshmpawar’s picture

Updated patch, removed the Cl error.

yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Status: Needs work » Needs review
FileSize
8.11 KB

same patch again for testing against boat.

Status: Needs review » Needs work

The last submitted patch, 28: document_all_arguments-2548049-27.patch, failed testing.

navneet0693’s picture

Component: Code » Miscellaneous

It shouldn't be code component I guess. Documentation component is not listed so changing it to Miscellaneous.

navneet0693’s picture

Status: Needs work » Needs review

The last submitted patch, 27: document_all_arguments-2548049-27.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 28: document_all_arguments-2548049-27.patch, failed testing.

navneet0693’s picture

So, if we are renaming captcha_api.txt to captcha.api.php, we need to make sure we have all syntax right.

21:36:31 PHP Parse error: syntax error, unexpected '.' in /var/www/html/modules/contrib/captcha/captcha.api.php on line 120

What's happening is DrupalCI is trying parse the file, and fails due to syntax errors as it considers it to a valid php file.

@Yogesh Pawar You might have to make the syntax right in file, specially convert this to string:

        $captcha['solution'] = ...
        $captcha['form'] = ...

Also you might have to club the examples of hooks implementation as there are multiple declarations. You can track syntax errors by using command:

php <filename>

utkarsh_malviya’s picture

I am a novice. Can someone help me to fix this?
Or is this assigned to someone else?

utkarsh_malviya’s picture

As someone is working on this issue! Can someone please redirect me to some novice unassigned issue?

navneet0693’s picture

@utkarsh_malviya Pick up documentation bugs on contributed modules as beginner :)

yogeshmpawar’s picture

Status: Needs work » Needs review
FileSize
674 bytes
8.49 KB

Thanks @navneet0693 for your comment #34.
please review this updated patch.

Status: Needs review » Needs work

The last submitted patch, 38: document_all_arguments-2548049-38.patch, failed testing.

yogeshmpawar’s picture

Status: Needs work » Needs review
FileSize
8.89 KB

Yet another patch to remove Cl error.

navneet0693’s picture

  1. +++ b/captcha.api.php
    @@ -99,89 +88,71 @@ function foo_captcha_menu($may_cache) {
    + *   on succes and FALSE on failure.
    ...
    + *   on succes and FALSE on failure.
    

    Let's not leave any stones unturned.

  2. +++ b/captcha.api.php
    @@ -189,19 +160,20 @@ insufficient for complex forms.
    +- 'path': path (array of path items) of the form's container element in which
    ...
    +- 'key': the key of the element before which the CAPTCHA element
    ...
    +- 'weight': if 'key' is not NULL: should be the weight of the element defined
    

    Indentation needs to be clear.

Nice work! Rearranging the implementation examples were indeed needed.

navneet0693’s picture

Status: Needs review » Needs work
yogeshmpawar’s picture

Status: Needs work » Needs review
FileSize
9.5 KB
13.9 KB

Thanks @navneet0693. Changes done as per comment #41

navneet0693’s picture

Status: Needs review » Reviewed & tested by the community

Good to go now :)

  • elachlan committed 198e7bc on 8.x-1.x authored by Yogesh Pawar
    Issue #2548049 by Yogesh Pawar, chishah92, rashid_786: Document all...
naveenvalecha’s picture

Status: Reviewed & tested by the community » Fixed

@elachlan, Did you forget to update the status?

hass’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev
Status: Fixed » Needs work
Issue tags: +Needs backport to D7

As noted several times in this case hook_captcha() has an undocumented 3rd argument and I need to know how this works. THIS was the ONLY reason why I opened this case.

naveenvalecha’s picture

Status: Needs work » Fixed
Issue tags: -Novice, -Needs backport to D7

@hass,
Thanks for opening that. Please open a new issue for 7.x

As per BC policy https://www.drupal.org/core/backport-policy#d7

Where an issue filed against 8.x also applies to 7.x, a separate issue should be opened against 7.x, related to 8.x via the 'Parent issue' field (this can be done using the "Add child issue" link on the 8.x issue).

yogeshmpawar’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
hass’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev
Status: Fixed » Needs work
Issue tags: +Needs backport to D7

This is not needed. This is the way how we handle issues for ages.

yogeshmpawar’s picture

@hass - i have created a child issue which applies on the branch 7.x-1.x-dev as per comment #48. Issue link #2842669: [D7] Document all arguments to hook_captcha() and fix broken documentation.

hass’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev

Reviewed D8 again and the 3rd argument still exists in code, but is not documented. So D8 is not fixed here!

hass’s picture

+++ b/captcha.api.php
@@ -0,0 +1,180 @@
+ *
+ * This documentation is for developers that want to implement their own
+ * challenge type and integrate it with the base CAPTCHA module.
+ * === Required: hook_captcha($op, $captcha_type='') ===
+ * The hook_captcha() hook is the only required function if you want to
+ * integrate with the base CAPTCHA module.
+ * Functionality depends on the first argument $op:
+ * 'list': you should return an array of possible challenge types that
+ * your module implements.
+ * 'generate': generate a challenge.
+ * You should return an array that offers form elements and the solution
+ * of your challenge, defined by the second argument $captcha_type.
+ * The returned array $captcha should have the following items:
+ * $captcha['solution']: this is the solution of your challenge
+ * $captcha['form']: an array of the form elements you want to add to the form.
+ * There should be a key 'captcha_response' in this array, which points to
+ * the form element where the user enters his answer.
+ * An optional additional argument $captcha_sid with the captcha session ID is
+ * available for more advanced challenges (e.g. the image CAPTCHA uses this
+ * argument, see image_captcha_captcha()) and it is used for every session.
+ * Let's give a simple example to make this more clear.
+ * We create the challenge 'Foo CAPTCHA', which requires the user to
+ * enter "foo" in a textfield.
+ */
+function foo_captcha_captcha($op, $captcha_type = '') {

We use @param to document APIs.

Captcha SID param is not documented and missing in the function call.

yogeshmpawar’s picture

@hass - i got your point, will change this & update the patch now.

yogeshmpawar’s picture

Status: Needs work » Needs review
FileSize
652 bytes

Updated patch as per comment #53

naveenvalecha’s picture

Priority: Normal » Minor
Issue tags: -Needs backport to D7

bumping its priority to normal

hass’s picture

Status: Needs review » Needs work

What is captcha session ID for and how does it work and what do I need to do as developer when I use it and how should I use it or for what. Nothing answered here. This is not helpful.

elachlan’s picture

Priority: Minor » Normal

Hass, I spent some time going through the code and as far as I can see this is what the $captcha_sid does.

The $captcha_sid is a unique identifier for an instance of the captcha. State information on each captcha session is stored in captcha_sessions, such as is solved status.

I'll leave it up to yogesh to do up another patch.

yogeshmpawar’s picture

Status: Needs work » Needs review
FileSize
524 bytes
815 bytes

Thanks @elachlan & @hass for the help to improve captcha.api.php, updated the patch as per comment #58 & #57

elachlan’s picture

There is a spelling mistake in there. It should say "such as its solved status."

We also need more information on how to use it. For instance because its unique to the session, image captcha uses it for a "static" url for the images for the captcha. The URL remains the same, but the image code changes.

I think @hass would agree that it is really up to the developer how they want to use the $captcha_sid, but at its base it really just uniquely identifies a session.

elachlan’s picture

Status: Needs review » Needs work
hass’s picture

We also need more information on how to use it.

I agree, this is still totally unclear to me.

couturier’s picture

joachim’s picture

I'm not sure I understand how this issue is working, as several commits seem to have been made but it's still in 'needs work'.

At any rate, there is an error in several of the hooks in the api.php file:

function foo_captcha_captcha($op, $captcha_type = '') {

The function name must start with 'hook_', not 'foo_'.

This breaks analysis tools such as the API module and Module Builder.

shubham.prakash’s picture

Status: Needs work » Needs review
FileSize
763 bytes

Change made as per #64

Anybody’s picture

Could someone please help with review here to get this fixed? I guess this also needs a reroll. Perhaps as MR then?

Grevil’s picture

Version: 8.x-1.x-dev » 2.x-dev
Grevil’s picture

Status: Needs review » Closed (duplicate)

I agree with @joachim in #64, I will create a new issue to fix the remaining issues.

CLOSED, duplicate of #3322230: Fix problems inside "captcha.api.php"