Problem/Motivation
25 days ago (October 29) we reached agreement on creating 8.x-2.x.dev release. This was based on a lengthy discussion in the Drop Libraries Dependency issue and some code I contributed. @Neslee was able to create a patch that applied from my code and we both confirmed in test systems that it appeared to work to remove the need for the contrib library module moving forward. This was an essential first step in getting a Drupal 9 compliant version of Juicebox.
Offline @Neslee recommended that I try the PHPCS (coding standards "module" (which mostly works from command line)). I have done that and have made many coding standards changes over the last 25 days. They were queued up on my local computer and testing system until last week when I put the whole batch of code out on Github at fkelly12054/juicebox-kelly (https://github.com/fkelly12054/juicebox-kelly). I am continuing to work on improvements to that. Anyone here should be able to download a set of the code from there.
In addition to removing the need for the contrib library module there are dozens (maybe hundreds) of relatively minor coding standards changes in there. There are a few issues relating to using dependency injection that are beyond my current pay level and expertise.
Many of the changes relate to translation. Prior to Drupal 9 you could make a simple "T()" call using a global function. Now you have to go through all sorts of machinations in order to do a "this->t". I think I've got most of that working but I'm sure experts will find corrections and improvements that can be made. I borrowed freely from how other modules did this since the abstract Drupal documentation provides almost no useful coding examples ... at least to people at my expertise level.
I've tested these changes both on a local Drupal (Wampserver) virtual host. I'm using Drupal 8.9.9 and also a separate virtual host with Drupal 9.08. I installed a base 9.08 system using composer and manually added in my version of Juicebox (the same code that's on my github area. On 9.08 I haven't created any Juicebox galleries yet ... I just tested the "backend" of Juicebox from both the admin/config screen and the Extend (Modules) screen. I ironed out a few Drupal 9 issues that way.
I don't think that creating a "mega" patch or a big series of patches is the way to go. They need to be committed anyway. I'd recommend maybe creating a separate branch with my code from Github then trying to set up a distribution with it. I'll be happy to test.
Juicebox and Drupal are the best solutions I've found for managing my photos. But the module has been neglected for several years now and the technical debt is showing. I will make whatever contribution I can to alleviating this.
Goals:
Port current stable D8 version to D9
Remaining tasks
N/A
User interface changes
N/A
API changes
N/A
Data model changes
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | Drupal_standard_practice.txt | 2.9 KB | fkelly12054@gmail.com |
Issue fork juicebox-3184078
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:
- 8.x-2.x
compare
- 3184078-moving-forward-from
compare
Comments
Comment #2
fkelly12054@gmail.com commentedP.S. to number 1. If there is anyone else out there (not a maintainer) who really knows the dependency injection stuff, I'd be happy to send a list of the programs that the standards compliance programs are complaining about. I think that if we could get these fixed up, we'd be a long ways towards having a great Drupal 9 compliant module.
Comment #3
fkelly12054@gmail.com commentedTo test further, and based on the code that's in the git referenced in #1 I used Composer to install a Drupal 9.0.8 site locally. Then I added in my Juicebox module. I created a juicebox gallery content type. I added in a photo gallery within that content type. It works ... you can view the photo gallery. You can configure Juicebox both from the extend screen and from the admin config screen.
There are still problems. I sure could use some help from a seasoned Drupal developer ... the output from the PHPCS standard practice is below showing what's left to do. There are two things that particularly concern me:
1. settingsform.php is not "injecting" the getLibrary function correctly. This is at lines 35 and 141. I've hacked away at it a bit but that's at the 5 propeller head level and I'm at most at 2.
2. juiceboxformatter.php is not injecting imagestyle properly. It's a variant of the problem above.
I think that in both cases I need a class with a function within them that can be used to inject the code. I just don't know how ... yet.
It would also be worth it for someone more expert to review the changes I've made to translations. In pre-Drupal 9 you could just use global t() function ... now you have to use a stringtranslationtrait thing and have a function that instantiates a string_translation variable. Then you can do a $this->t in place of a t() and Drupal won't complain. What I've done so far seems to work but I'm not sure I haven't created some unnecessary or duplicate code along the way. Better not to have that on 10k sites a few years from now.
There are a few other nits pointed out by phpcs ... unused variables for instance. I'm not sure these need fixing and if so what the right approach would be.
This all needs a lot more testing than I can do by myself ... I will have to rely on our maintainer and others to step in. We might want a 8.9x release that removes use of the contrib library module and then a 9.x release. People who have other blockers to using Drupal 9 could use the 8.9 release ... those who don't could test the Drupal 9 release.
Comment #4
D4K0 commentedWell, as for the dependency injections (lines 35&141), I think I can help you get forward with that stuff.
Generally, we firstly need to register the service dependency in juicebox.services.yml.
I've noticed it'd been already done.
Secondly, we need to inject it into the form class in its constructor method.
Not tested example with my comments included.
Just give it a try and let me know if it works.
If not, I'll have to clone the project and do more debugging on this topic.
IMHO, I'll have to do that anyway as I'm using Juicebox across my D8 projects quite often currently and I'd like to use it for my upcoming D9 projects as well (without applying the bunch of personal and community patches...).
Comment #7
D4K0 commentedI think we're on the right track now.
Anyway, it gonna take much more effort to break the ice finally.
Many tests are still failing...
Comment #8
D4K0 commentedComment #9
D4K0 commentedComment #10
D4K0 commentedFailed tests concerning unsupported PHP vesrions doesn't matters.
It looks like it's OK with D8.9
Those concerning D9 needs to be tracked and resolved.
Comment #11
D4K0 commentedWell, this attempt was partially successfull. We've passed PHP 7.4 & MySQL 5.7 and D9.1 as well as PHP 7.4 & MySQL 5.7, D8.9
Comment #12
fkelly12054@gmail.com commented@dk40 ... waking up to your posts today gives me hope! Thanks. I'm reading text books as I go re. dependency injection so having some guidance is great. I will try your suggestions out. If I can make them work locally I'll put them up on my github account where I have the code that removes the contrib module library dependency and MANY FIXES identified by PHPCS (code sniffer).
We need our maintainer's expertise and collaboration on getting commits done in the "official" Drupal dot org version. Hopefully he can use what I've put out on github (linked elsewhere) so no one else has to go through the phpcs listings and fix things all over again.
The one code statement that's brought me to a screeching halt is in the JuiceboxFormatter.php program in the function named styleimage (at line 293 in my version of the code and down at line 333 there: " $style_obj = ImageStyle::load($style_each);" ... by my reading this is saying "load parent" from Imagestyle and should probably be loading in a styles from a style object. I'm trying to figure out exactly what the context of this is. From the comment preceding the function I think that this function is only used when you are trying to use an individual image file that you've uploaded with the juicebox formatter. I never encounter this because I load my galleries whole using FTP and there should be no need to "style" individual images. That may be why I can run the code on Drupal 9 without issues too?
I will see if I can integrate your suggested code into my version of juiceboxFormatter and remove this problem. I'll be back.
Comment #13
fkelly12054@gmail.com commentedOops. Looking at your code @dk40 i can see you were working on the dependency injection issues in settingsform.php. Sorry: I've been totally consumed focusing on the issue in juiceboxformatter.php. I will switch gears and try your suggestions with settings form. The coding standards stuff is showing three dependency injection issues: one in juiceboxformatter and two in settings form. Once these are done we should be able to test against Drupal 9. No guarantees what we'll find.
Comment #14
D4K0 commentedReading your posts I've got the feeling the dependecy injections are the biggest troubles in moving forward to D9 version.
So I've focused primarily on this topic.
Btw. I'm D4K0. It's an acronym. Something like F4K3. Nice to meet you :)
Comment #15
D4K0 commentedWe've passed D8.9 and D9.1 tests. That's nice.
D9.0 needs more work.
Comment #16
fkelly12054@gmail.com commented@dk40 Testing your code for settingsform.php I am getting:
I first "hand-merged" your code into mine, then when I had the error above I just copied and pasted your code entirely into mine. Still showing the error. My services.yml is:
which is only different from yours in including the messenger (which I think is needed somewhere).
Comment #17
D4K0 commentedThanks for your error messages. It looks like the service parms are given in the incorrect order. Needs refactoring.
I'll try to fix it soon. I'll have to setup my own dev.env. definitefly.
Comment #18
D4K0 commentedWell, I'll give it the last 'blind' try today.
Comment #19
D4K0 commentedHow about this? Does it work on your side?
Comment #20
D4K0 commentedThis docs might be helpful
https://www.drupal.org/docs/drupal-apis/services-and-dependency-injectio...
Comment #21
D4K0 commentedAs for Drupal Coding Standards, 'Unused variables' mentioned in Drupal Standrard Practice.
Warnings should be definitefly fixed. Still, the dependecy injections are our prior issue these days.
Comment #22
fkelly12054@gmail.com commentedThe website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\juicebox\Form\SettingsForm::__construct() must be an instance of Drupal\juicebox\Form\JuiceboxFormatterInterface, instance of Drupal\juicebox\JuiceboxFormatter given, called in D:\webpage\drupal8\modules\juicebox\src\Form\SettingsForm.php on line 41 in Drupal\juicebox\Form\SettingsForm->__construct() (line 30 of modules\juicebox\src\Form\SettingsForm.php).
Drupal\juicebox\Form\SettingsForm->__construct(Object) (Line: 41)
Drupal\juicebox\Form\SettingsForm::create(Object) (Line: 28)
Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition('\Drupal\juicebox\Form\SettingsForm') (Line: 48)
Drupal\Core\Controller\HtmlFormController->getFormObject(Object, '\Drupal\juicebox\Form\SettingsForm') (Line: 76)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
This is based on the code from commit c8b9d068 copied and pasted directly into my SettingsForm.php file in order to avoid an transcription/ copy/paste type errors. I'm back to working on it. I will look at unused variables issues once we get past these three dependency injection errors. I have a sneaking suspicion that other modules, and even core modules that have been "certified" for Drupal 9 may have these same type of errors generated in foreach loops. If not, I'll see how they fixed it.
I'll be working to see if I can figure out anything from your changes the rest of the East Coast U.S. time this afternoon. If we can get the two issues in settingsform and the one in juiceboxformatter fixed I think we will be in good shape.
Comment #23
fkelly12054@gmail.com commented@dk40 ... the document you listed on services and dependency injection does seem focused in the right area. I'll need to absorb it. I have two text books open also. I have been puzzling over "Argument 1 passed to Drupal\juicebox\Form\SettingsForm::__construct() must be an instance of Drupal\juicebox\Form\JuiceboxFormatterInterface" and trying to find work arounds. Where it gets (and inserts) the word "Form" in that puzzles me.
Tomorrow will be another day.
Comment #24
fkelly12054@gmail.com commentedaha. So, I took a fresh look at your latest commit @dk40 and compared line by line with the code I had copied from it and tested with. Yesterday I "fixed" up the two standards suggestions from https://www.drupal.org/pift-ci-job/1898572
This morning I decided to take the error message generated when I tested the code seriously and work backwards. So I changed the construct statement to:
where the commit code was constructing JuiceboxFormatterInterface. That seems to work on my test system when I go to configuration/juicebox and a configuration form is generated.
I'll post the full text of the code I'm using for settingsform.php in a separate post. Then I'll test some more and run things back through PHPCS. I'll have to study some on what merge requests do versus patches etc. I have a full version of the changes I'm making on my github page though I haven't updated it for yesterday and today's changes ... that are in flux.
Comment #25
fkelly12054@gmail.com commented11/30/2020 version of settingsform.php per #24 edited to fix two coding standards issues
Comment #26
fkelly12054@gmail.com commentedre. coding standards ... I just ran a bunch of modules, both contrib and those that come in core/modules through the DrupalPractice option of the Standards. There are plenty of unused variables and many dependency injection issues. Most common is "t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead". I think that I've eliminated that last one entirely from my version of Juicebox that can be found on my github site. I may not have done that elegantly since it was my first crack at dependency injection so a review by more experienced developers would be welcome as we move towards publishing this.
Comment #27
D4K0 commentedNice to see some progress here! :)
THX for debugging & code-reviewing my 'blind' code, Frank.
Firstly, I definitely need to set up my own local dev.env (and get my act together).
I'm quite busy on weekdays recently. Used to be volunteering mostly on weekends only.
Anyway, I've already both made up my mind to get this issue done at all costs and
got the feeling we are capable to make it finally!
Let's sort 'soft' things at first.
You've mentioned we don't have maintainers privilages to this issue, so that you set up your own fork.
To develop together we need develop on the same code-base.
Since we are not fully approved to manage this issue fork, I suggest all commits to this issue will go to your fork.
You as the maintainer will be responsible for Coding Standards Review, branch merging etc.
Until we finally get it to the stable D8.9/D9.
The link to your repository should be placed here in significant manner to let the other community
members know at first sight, they need to commit to your repository instead of the official one.
At least, until we get it fully in compliance with D9 standards. That means acceptable by the contrib.module maintainers and ready to the official release.
Comment #28
D4K0 commentedI'll make the attempt to dig deeper in to the dependency injections stuff blockers and move it forward this weekend. Hopefully...
Comment #29
D4K0 commentedIf there's anybody here, reading this posts, willing to contribute and being familiar with Drupal8/9 Dependency Injections,
please join us to make Juicebox HTML5 Responsive Image Galleries stable at D9 as soon as possible!
Any help would be greatly appreciated!
A lot of work has been already done.
Dependency injections are the main blockers at the moment.
Comment #30
fkelly12054@gmail.com commentedMy github repository is at:
https://github.com/fkelly12054/
I will be happy to add anyone as a collaborator. My repository is just a stopgap measure ... I have no intention of trying to replace the official Drupal repository for juicebox that's here on drupal.org. Nor do I have the expertise to do so.
DK40 contributed code that got me 90 to 95 percent of the way to resolving the dependency injection issues in settingsform.php. After some fumbling around this morning (11/30) I made one more change that got us over the line ... at least on my local test system.
The only other dependency injection issue is in Juiceboxformatter.php. I'm working on that. I'm reading the book as I go, so if anyone can contribute that will be helpful.
I don't think there are a lot of other changes to make. Then we will need our maintainer to make a commit. I'm pretty sure we can do a commit that (a) resolves non-trivial coding standard issues, (b) takes care of all dependency injection issues (c) removes library dependency and (d) is Drupal 9 compatible. But we won't know it until we do it. I'm sure we'll want some kind of beta or test release so people can run it through the wringer. I don't use all the features of Juicebox and it's hard for me to test.
For at least the last week I've been able to run the code that's now on github on my localhost Wampserver. I have a Drupal8 (8.9.9) system and a Drupal 9.0.9 system set up. I think the reason I'm not running into issues on Drupal 9 so far is because I'm not executing the portions of code that have dependency injection issues. But we'll see.
Comment #31
fkelly12054@gmail.com commentedjust a quick progress report from #30. DK40 has resolved the dependency injection issues and we have cleared up almost all coding standards issues that are reported by phpcs (code sniffer). There are some inconsistencies within code sniffer that may keep us from getting to 100% but nothing remaining is critical.
My github page is a decent intermediate location for working things out but eventually we will need to get everything back on Drupal dot org.
Comment #32
D4K0 commentedIssue summary updated.
Comment #33
fkelly12054@gmail.com commentedGenerally, as of 12/8/2020, we are making good progress on the "moving forward" project. There are a couple of Drupal 9 compatibility issues to be sorted out and one roadblock we just discovered on 12/7.
The roadblock is this: in the removing libraries dependency issue, I moved and revised all the code from the contrib libraries module that detected where the libraries js for Juicebox was located and built the appropriate $libraries variable. That's now inside the juicebox module in juiceboxformatter.php and the juicebox module. As far as I know, that works well.
The problem is this: there are two supported ways to build a Juicebox gallery. One is to embed it within a content item (often named Juicebox Gallery) but the name is irrelevant. Then use the embed instructions within each content item:
https://www.juicebox.net/support/embedding/
These instructions result in loading the juicebox library for each content item e.g.,
<script src="jbcore/juicebox.js"></script>It works fine, though is perhaps a bit redundant. Separate longer term issue but I think this means should be replaced once we are safely on Drupal 9.
The second way to build a gallery is to use the Juicebox field formatter and add individual images (or media items) to the Gallery. Instructions for that are in the Juicebox documentation. The problem with this approach is that it doesn't assure that the juicebox js library is added to each item. The contrib library module took care of this.
So now the issue is: what's the best way of doing this. Options: (1) use the juicebox.libraries.yml file? It might work, but then I think it would be loading the library on every page load of a Drupal site. It would be better to only load it when an actual gallery is loaded.
(2) Duplicate the load that's used in the juicebox embed (above) and put it in juicebox-embed-twig-html script. I've experimented with that. But we allow the library file to be in either /libraries/juicebox or /sites/all/libraries/juicebox. So we'd have to have the embed load whichever of those locations was appropriate.
(3) Replicate some of the contrib module logic for loading a library over into the juiceboxformatter.php and or juicebox.module. There is a lot of code in there that we don't need: we've already detected where the library files are. Unfortunately it appears the contrib library module uses a deprecated function:
Removing this is a todo in the libraries module and most likely something we need to do going forward. But how? I'm looking for recommendations.
(4) Another approach?
I'm open to suggestions. I (or my colleague DK40 who has been helping right along) will do the implementation and test over on my github site, test it there and we should be ready for @Neslee to move a copy back over here.
We have already removed almost all coding standards issues and dependency injection issues and tested on both Drupal 8.9.x and 9.09 and 9.1. This is still going to need further testing by the community here and at least one beta (dev) type release before it's ready for prime time.
Comment #34
fkelly12054@gmail.com commentedThe drupal_add_js function was for Drupal 7 and shouldn't be used here. I tried anyway ... just generates an error.
Sticking the
<script src="/sites/all/libraries/juicebox/juicebox.js"></script>in the twig embed file seems to work. But we'd need to, at a minimum, make it a variable with the content based on where the library is stored. Seems ugly to me.I'm not sure if putting the load in the libraries.yml is desirable. Think not.
In the juiceboxformatter.php getlibrary function we "discover" reliably where the library is. I just can't figure out how to load it from there.
Not sure it it would be okay to just copy the library js file to the juicebox/js directory and load it from there.
Kind of stuck.
Comment #35
fkelly12054@gmail.com commentedStill looking into this:
https://www.drupal.org/node/2274843
Adding stylesheets (CSS) and JavaScript (JS) to a Drupal module
is the reference document we need. How to implement this is an open question (to me). I've tried a libraries.yml that looks like this:
But it's not at all clear to me when that file actually gets processed in the Drupal page loading sequence.
The old contrib module libraries (filename: libraries.module.php) had a load function. But that's deprecated. I'm having trouble even tracking down where it was executed in the old code.
We need to apply one or more of the techniques in https://www.drupal.org/node/2274843. But then we need to make sure they don't conflict or overlap the embed instructions for pre-built galleries.
One problem is that neither the Juicebox or the libraries module has been truly maintained in years ... like 3 of them.
Comment #36
neslee canil pintoNew branch and release for drupal 9 support - https://www.drupal.org/project/juicebox/releases/8.x-3.0-alpha1
Comment #37
neslee canil pintoComment #38
neslee canil pintoThanks for the work flekky and DK
Comment #39
neslee canil pintoWe can follow up on #3042821: Drupal 9 Deprecated Code Report
Comment #40
neslee canil pinto