Problem/Motivation
For some reason, "ImageCaptchaConstants" won't get recognized inside image_captcha.install on installation, leading to:
Error: Class "Drupal\image_captcha\Constants\ImageCaptchaConstants" not found in image_captcha_requirements() (line 20 of modules/custom/captcha/modules/image_captcha/image_captcha.install).
The correct folder and namespace structure is present and correctly applied, as the "captcha" uses the exact same folder / namespace structure, which works flawless.
So either a dedicated "Constants" folder does not work properly for submodules, or Constants should reside inside a different folder entirely.
Steps to reproduce
Proposed resolution
Temporarily move all image captcha constants in to the captcha constant class and resolve this problem later.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork captcha-3321215
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:
Comments
Comment #3
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedTemporarily fixed the problem, by moving all image captcha constants into the captcha constants class.
Setting this back to normal, as the image_captcha module is installable again.
Comment #4
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedThe module "etracker" uses a "Helper" folder / namespace where a Constants class is defined in, but this also does not work for submodules (https://git.drupalcode.org/project/etracker/-/tree/8.x-3.x/).
Comment #5
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedNote, using the Constant via "\Drupal\image_captcha\Constants\ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB" inside the install file is against the Drupal coding standards ("Namespaced classes/interfaces/traits should be referenced with use statements") and does not work either.
Comment #6
corE CreditAttribution: corE commentedJust throwing in info from my update experience, if needed/helpful.
Updating CAPTCHA 8.x-1.6 to 8.x-1.7
The update page downloaded the module and than I got a white page with message:
The website encountered an unexpected error. Please try again later.
AssertionError: The file specified by the given app root, relative path and file name (.../modules/captcha/image_captcha/image_captcha.info.yml) do not exist. in assert() (line 67 of core/lib/Drupal/Core/Extension/Extension.php).
Seems it wants the image_captcha folder/files, which was not in the update. There was a new folder named ".tugboat" with one file "config.yml" which was not in 8.x-1.6 version.
I reinstalled the 8.x-1.6 version to get back to normal.
- Drupal Version 9.4.8
- PHP Version 8.1.12
Thank you.
Comment #7
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commented@corE, thanks for the info! Have you tried clearing all caches and running "drush updb"?
I have not touched the module file in the newest release, as you can see here. Also, the tugboat integration is already present in 8.x-1.6. Only moved some constants for 8.x-1.7 release.
Please create a separate issue if this is still a problem.
Comment #8
Anybody@corE I think you accidentially updated to 2.x. At least that would fit the error message.
https://git.drupalcode.org/project/captcha/-/tree/8.x-1.x shows, the path you mentioned exists. Anyway I don't think that's related to this issue.
@Grevil how to proceed here? Simply close this fixed and keep as-is?
Comment #9
corE CreditAttribution: corE commentedThank you Grevil... & Danke Anybody (I saw the German marker).
Sorry, I may have misinterpreted this posting destination here.
I will take your suggestions and try again.
- I did clear caches before updating, but I will try after the file replacement step to see if that helps.
- I didn't see tugboat folder in the 8.x-1.6 version that I had installed prior, and reinstalled.
- Anybody mentioned "accidentally updated to 2.x", but I'm not seeing a 2.x for anything. Hum?
Thank you for your help! I will sign out of this thread here and try updating again. If the issue I'm having is still there I will do as you recommend and create a separate issue.
Comment #10
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedNo worries @corE and happy coding!
@Anybody I guess so! Since it probably is once again a submodule problem...
Comment #11
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedComment #12
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedReopening this issue, as it leads to a minor issue, trying to directly install the image_captcha submodule in #3321215: "ImageCaptchaConstants" won't get recognized inside image_captcha.install.
Comment #13
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedOK, I think I know how to fix this. The "ImageCaptchaConstants" class inside the submodule's "Constants" folder is not the problem, the only problem is the Constant used in the install file. Constants inside install files should be avoided, as this file is loaded before any php files of the module are loaded in. So when the install file executes, it doesn't know about the Constant, because the ImageCaptchaConstants.php hasn't loaded yet.
Comment #15
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedShould be fixed now, module still works as expected while testing it manually.
Please review!
Comment #16
AnybodySuper cool, let's see what the tests say!
Should the constants have comments btw?
Comment #17
AnybodyCode looks good and tests are passing now!
But still the questions:
I think they are self-explaining but perhaps comments would make sense?
Comment #18
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commented@Anybody, originally they had none. Furthermore, the use case for a few of them is pretty "debatable", see #3324321: Replace bitwise operations in if clauses related to "_image_captcha_check_setup" calls.
I am not sure if using bitwise operations in such a high level programming language as PHP serves any purpose...
Comment #19
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedI'll commit this as is for now.