Right now Image CAPTCHA settings form has lots of errors, also menu tasks are not defined.

Issue fork captcha-2501699

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

m1r1k’s picture

Status: Active » Needs review
FileSize
2.21 KB
m1r1k’s picture

And now with required files :)

Berdir’s picture

+++ b/image_captcha/image_captcha.links.menu.yml
@@ -0,0 +1,6 @@
+  title: 'Image CAPTCHA'
+  description: 'Image CAPTCHA module settings.'
+  route_name: image_captcha.settings
+  parent: captcha.settings
+  weight: 10
diff --git a/image_captcha/image_captcha.links.task.yml b/image_captcha/image_captcha.links.task.yml

diff --git a/image_captcha/image_captcha.links.task.yml b/image_captcha/image_captcha.links.task.yml
new file mode 100755

new file mode 100755
index 0000000..3f25d46

index 0000000..3f25d46
--- /dev/null

--- /dev/null
+++ b/image_captcha/image_captcha.links.task.yml

+++ b/image_captcha/image_captcha.links.task.yml
+++ b/image_captcha/image_captcha.links.task.yml
@@ -0,0 +1,4 @@

@@ -0,0 +1,4 @@
+image_captcha.settings:
+  route_name: image_captcha.settings
+  title: 'Image CAPTCHA'

You don't need both a menu link and a local task, IMHO, just a local task should be enough.

The last submitted patch, 1: captcha-image-captcha-settings-form-2501699-1.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 2: captcha-image-captcha-settings-form-2501699-2.patch, failed testing.

Status: Needs work » Needs review
elachlan’s picture

Could you re-roll the patch with only the local task?

Berdir’s picture

Status: Needs review » Needs work
ddrozdik’s picture

Assigned: m1r1k » ddrozdik
Status: Needs work » Needs review
FileSize
3.75 KB

I have updated the patch.

Berdir’s picture

Status: Needs review » Needs work
  1. +++ b/image_captcha/src/Form/ImageCaptchaSettingsForm.php
    @@ -80,7 +83,7 @@ class ImageCaptchaSettingsForm extends ConfigFormBase {
         ];
         // RTL support option (only show this option when there are RTL languages).
    -    $languages = language_list('direction');
    +    $languages = \Drupal::languageManager()->getLanguages();
         if (isset($languages[Language::DIRECTION_RTL])) {
    

    This is not the same, the old call was about checking if there are languages that do RTL, this will never be TRUE now.

  2. +++ b/image_captcha/src/Form/ImageCaptchaSettingsForm.php
    @@ -299,19 +302,20 @@ class ImageCaptchaSettingsForm extends ConfigFormBase {
           $default_fonts = _image_captcha_get_enabled_fonts();
    +      $conf_path = DrupalKernel::findSitePath(Request::createFromGlobals());
           $form['image_captcha_fonts'] = [
    

    You shouldn't create a new request, just have it injected by adding Request $request to the buildForm() method.

ddrozdik’s picture

OK, I have updated the patch and added more modifications. Currently page works correctly.

ddrozdik’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 12: captcha-image-captcha-settings-form-2501699-12.patch, failed testing.

naveenvalecha’s picture

Issue tags: +Needs reroll
ddrozdik’s picture

ddrozdik’s picture

Status: Needs work » Needs review
naveenvalecha’s picture

Status: Needs review » Needs work
  1. +++ b/image_captcha/src/Form/ImageCaptchaSettingsForm.php
    @@ -80,8 +83,8 @@ class ImageCaptchaSettingsForm extends ConfigFormBase {
    +    $language = \Drupal::languageManager()->getCurrentLanguage();
    

    same here inject the @language_manager service.

  2. +++ b/image_captcha/src/Form/ImageCaptchaSettingsForm.php
    @@ -296,36 +299,47 @@ class ImageCaptchaSettingsForm extends ConfigFormBase {
    +      $conf_path = DrupalKernel::findSitePath($this->getRequest());
    

    Please inject the @kernel service.

  3. +++ b/image_captcha/src/Form/ImageCaptchaSettingsForm.php
    @@ -296,36 +299,47 @@ class ImageCaptchaSettingsForm extends ConfigFormBase {
    +      $conf_path = DrupalKernel::findSitePath($this->getRequest());
    
    @@ -383,14 +397,14 @@ class ImageCaptchaSettingsForm extends ConfigFormBase {
    +        DrupalKernel::findSitePath($this->getRequest()) . '/libraries/fonts',
    

    same as above. please inject the @kernel service

Edit : oops please ignore 2,3 those are static methods so no need to inject the service.

ddrozdik’s picture

Status: Needs work » Needs review
FileSize
9.54 KB

@naveenvalecha your are right. I have update the patch.

naveenvalecha’s picture

hass’s picture

Status: Needs review » Needs work
  1. +++ b/image_captcha/src/Form/ImageCaptchaSettingsForm.php
    @@ -296,36 +335,48 @@ class ImageCaptchaSettingsForm extends ConfigFormBase {
    +        $available_fonts[$font['uri']] = '<img' . new Attribute($attributes) . ' />';
    

    This should be a render array (the upgrade path from theme_image()

  2. +++ b/image_captcha/src/Form/ImageCaptchaSettingsForm.php
    @@ -296,36 +335,48 @@ class ImageCaptchaSettingsForm extends ConfigFormBase {
    +        'font_preview' => '<img' . new Attribute($attributes) . ' />',
    

    render array

  3. +++ b/image_captcha/src/Form/ImageCaptchaSettingsForm.php
    @@ -383,14 +434,15 @@ class ImageCaptchaSettingsForm extends ConfigFormBase {
    +        $fonts[md5($filename)] = (array) $font;
    

    Since Drupal 7 we should not use md5 - use sha2 only.

ddrozdik’s picture

item #3 will be fixed in this issue https://www.drupal.org/node/2486113

elachlan’s picture

Could you re-roll the patch with the fixes please?

elachlan’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

Utilvideo’s picture

Error
Drupal\Core\Config\UnsupportedDataTypeConfigException: Invalid data type for config element image_captcha.settings:image_captcha_fonts_preview_map_cache.3438abc85ac58eaab01cd741b1c3f9bb5dd3b9be3c079b1a7851884135608b2f in Drupal\Core\Config\StorableConfigBase->validateValue() (line 160

Utilvideo’s picture

Problem is in this method
$form['image_captcha_font_settings'] = $this->settingsDotSection();

harald_’s picture

Hi, that is unfortunately not fixed. Please reopen this issue.

The settings page cannot be accessed via the backend, the error message appears as described by Regnoy.

Anybody’s picture

@Maintainer, @Regnoy & harald_ have you tried the latest dev? Does the problem still exist there?

If everything is OK in dev, lets please create a new stable release
If it's not OK, could the maintainer please re-open the issue?

Anybody’s picture

@elachlan / Maintainer: I just checked this myself. The current dev does not work, the image captcha settings form does not appear in the navigation / tabs. We'll need a follow-up patch. Please re-open this issue to have the still existing problem / context.

Anybody’s picture

As temporary workaround you can set the values using devel config editor: /devel/config/image_captcha

elachlan’s picture

Status: Closed (fixed) » Needs work
couturier’s picture

yogeshchaugule8’s picture

Status: Needs work » Needs review
FileSize
8.5 KB

I've created a patch by using existing available configurations. Following issues are updated in patch :

  • Child menu link for "Image Captcha" is visible under Captcha in Admin Toolbar
  • Added "Image Captcha" tab on Captcha Settings Page
  • Fix coding issues.
  • Updated form submit to save configurations.
jernejbeg’s picture

Status: Needs review » Needs work

Patch fix_image_captcha_settings-2501699-36.patch does not apply. Marking this as Needs work.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
8.46 KB
rpayanm’s picture

Issue tags: -Needs reroll
Anybody’s picture

Hi @rpayanm - could you please provide an interdiff? You posted a patch without any comment, so we can't understand, what changed. Thank you!

Anybody’s picture

Status: Needs review » Needs work

I tried the patch in #38 and found the following issues:

  1. No font preselected => Blanko Captcha generated
  2. I get the notice:
    User warning: The following theme is missing from the file system: captcha_image in drupal_get_filename() (Zeile 295 in drupal8/web/core/includes/bootstrap.inc)

    on the settings page.

  3. The folder structures sites/all/libraries/fonts oder sites/default/libraries/fonts are a bit untypical for Drupal 8 / 9 I guess? Much more untypical is libraries/fonts. I'd suggest to let the user enter the path, which allows to download custom font libraries via composer and set them? libraries/x is typically used for composer'ized libraries with their fixed names. In that case the descriptions would have to be aligned.

Anyway I can confirm that the patch works and creates a configuration page, which is much better than none... but the 1st and 2nd point should be fixed first to prevent broken captcha.
I'd vote for a first "working" solution and follow-up improvements to at least have the Drupal 7 status.

Thank you all very much!

rahulrasgon’s picture

Assigned: ddrozdik » rahulrasgon
rahulrasgon’s picture

Assigned: rahulrasgon » Unassigned
Status: Needs work » Needs review
FileSize
10.08 KB
1.61 KB

Please review the patch.

Following issues are updated in patch :

  • No font preselected : This issue was due to on module install image_captcha_fonts stores the file path in the config, and on form we are rendering the hash value as options.
  • User warning:

    User warning: The following theme is missing from the file system: captcha_image in drupal_get_filename() (Zeile 295 in drupal8/web/core/includes/bootstrap.inc)

    This warning was due to incorrect library name used.

Thanks

Anybody’s picture

Whao @rahulrasgon GREAT work!
Fixes the mentioned problems in #41.

One thing I didn't see before is the part of the patches from #36 on, which remove the protected method and replace them by a functional function. I can't see a good reason for that in Drupal 8 / 9 and it should be reverted.

Thanks a lot for your effort! Really looking forward to this!

Perhaps we can soon have maintainer feedback on this? @elachlan?

sanjayk’s picture

Assigned: Unassigned » sanjayk
Status: Needs review » Needs work
sanjayk’s picture

Assigned: sanjayk » Unassigned
Status: Needs work » Needs review

Sorry now I am busy some other task will resume later.

Inaetaru’s picture

I'm sorry, but #43 breaks compatibility with Drupal 9. It uses file_scan_directory in _image_captcha_get_available_fonts_from_directories (instead of original $this->fileSystem->scanDirectory in getAvailableFontsFromDirectories), but the method is deprecated in Drupal 8 and removed in Drupal 9.

Anyway, thanks a lot for all your work!

Berdir’s picture

Status: Needs review » Needs work
sanjayk’s picture

@berdir as per #47 have replace depreciated function and creating a new patch for D9.

sanjayk’s picture

Status: Needs work » Needs review
FileSize
10.24 KB
936 bytes

@Berdir Please ignore #49 patch. I have fixed the and uploading new patch and interdiff.

jernejmramor’s picture

Anybody’s picture

Using #50 for nearly three months now and it adds back the important image captcha form missing since 7.x so I'd definitely vote to finally review and commit it.
One could discuss to put _image_captcha_get_font_uri into a class or similar but let's be honest, this is now missing since years at all, situation won't get worse ;)

nmatja’s picture

I have tested the fork update. Listed updates are working for me.

Anybody’s picture

Status: Needs review » Reviewed & tested by the community

RTBC for the reasons given in #52. Anyway there's still space for improvement and additional tests, if someone would like to take that little but important project. :)

Any Captcha maintainer in this issue to finalize RTBC and commit this?

Thank you all!

japerry’s picture

Status: Reviewed & tested by the community » Fixed

50 looked good to me as well. Committed!

  • japerry committed aa9e22f on 8.x-1.x authored by sanjayk
    Issue #2501699 by ddrozdik, sanjayk, naveenvalecha, m1r1k, rahulrasgon,...
Anybody’s picture

Whao this is important news after years without proper configuration for Captcha image!

We should now focus on improvements and tests for that functionality as follow-up. Thank you very very much for commiting this @japerry!

Status: Fixed » Closed (fixed)

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