Problem/Motivation
Error: Call to undefined method Drupal\Core\Database\Driver\mysql\Connection::getConnection() in Drupal\abjs\Form\AbjsConditionForm->saveCondition() (line 171 of modules/contrib/abjs/src/Form/AbjsConditionForm.php)
Update: also a similar issue when attempting to submit AbjsTestForm.php
Steps to reproduce
Set up new condition at /admin/config/user-interface/abjs/conditions and attempt to save it.
Set up the test at /admin/config/user-interface/abjs and attempt to save it.
Proposed resolution
Comparing the file in question with AbjsExperienceForm.php, which works fine, noticed the following differences.
1. use declaration on line 5 can be removed: 'use Drupal\Core\Database\Database;'
2. Database queries that include '$this->database->getConnection()->' should be simplified to '$this->database->' on AbjsConditionForm.php and AbjsTestForm.php
You're welcome :)
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | abjs_fix_deprecated_method-3198542-15.patch | 14.43 KB | inaw |
| #13 | fix_deprecated_method-3198542-12.patch | 29.59 KB | nsalves |
| #11 | fix_deprecated_method-3198542-11.patch | 29.34 KB | nsalves |
| #7 | unecessary-getConnection-method-3198542-7.patch | 8.03 KB | vipin.mittal18 |
| #4 | abjs-after-apply-patch-configuration.PNG | 31.46 KB | vipin.mittal18 |
Comments
Comment #2
bobiroka commentedComment #3
bobiroka commentedComment #4
vipin.mittal18Hello Matt Mowers,
I have applied the patch and verified the functioning. It looks good to me and good to apply the patch. Refer attached screengrab
Thanks
Vipin
Comment #5
vipin.mittal18Comment #6
avpadernoThe patch in #3 applies to the development branch too.
Comment #7
vipin.mittal18I believe the development branch https://www.drupal.org/project/abjs/releases/8.x-1.x-dev doesn't have latest code which 8.x.1.3 has.
I have renamed the patch as per the guidelines and attached in this comment.
Comment #8
avpadernoOn Drupal.org, a release is created from a Git branch. A release cannot have code that is more recent of the code contained in the corresponding Git branch.
The exact steps to create a new release are:
Comment #9
avpadernoWhy is the file renamed? Fixing code in a file doesn't require to rename it.
Drupal would not even use the new.AbjsConditionForm.php file to load the
AbjsConditionFormclass. A class whose fully qualified name is\Drupal\abjs\Form\AbjsConditionFormis loaded from the src/Form/AbjsConditionForm.php file.Comment #10
avpadernoThe patch should also correct code similar to the following one, present in the module classes.
Instead, the code should add the dependency on
create().The class constructor, in this case for the
Drupal\abjs\Controller\AbjsDefaultControllerclass, should be accordingly changed.Comment #11
nsalves commentedHey guys,
I found that the type of problem described here occurred in more files than the ones fixed in #7 so I attached a new patch that hopefully fixes all the problems with the deprecated method.
Comment #12
nsalves commentedComment #13
nsalves commentedForgot to remove an unused class import, new patch attached. All should be fine now.
Comment #14
avpadernoAt first sight, it seems fine.
Comment #15
inaw commentedI wasn't able to apply the lasted patch #13 https://www.drupal.org/files/issues/2021-03-18/fix_deprecated_method-319... because it has special characters in it.
I tried to fix it and re-uploaded the patch.
Comment #16
matthieuscarset commentedPatch in #15 works correctly.
Tested on Drupal
8.9.13with ABJS1.3.0.Comment #18
thallesThanks everyone!
Comment #19
thalles