Closed (fixed)
Project:
Mother May I
Version:
7.x-1.6
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
2 Feb 2017 at 18:27 UTC
Updated:
2 Mar 2017 at 02:52 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
dwillcox commentedPlease see issue #2794919.
Long story short, yes, I want to do this. I'm having trouble working through D8 APIs, though. I'm working on another, much simpler, module first. Once I get that to work, I'll start on this.
Comment #3
dwillcox commentedOh. No. Wait. I got projects confused.
Actually, this is the "simpler" module I referred to in my previous comment.
So, yes, working on this. No success so far.
Comment #4
hansfn commentedOK. What about creating a 8.x branch and committing whatever you have. Then I and other people can chip in.
Comment #5
dwillcox commented@hansfn - That seems like a really good idea.
(Yahoo seems to want to mark email from drupal as spam, so I don't always see it.)
So I pushed to a new 8.x-1.x branch. It's nonfunctional, but pieces work. I'll keep playing with it, but please take a look and see if you know what's wrong.
See the README.md.
Comment #6
hansfn commentedGreat. You could create a dev release as well so we can create issues against the 8.x-1.x version.
I have created a "Drupal 8 Contrib Porting Tracker" issue - #2851027: [mothermayi] Mother May I.
Comment #7
hansfn commentedPatch for menu link problem attached.
Comment #8
dwillcox commentedhansfn thank you!
Though there was something else going on than just this. I'm pretty sure that was one of a bunch of different versions. I applied the patch, still no joy. I tried clearing caches, and uninstall/install. Still, no joy.
Then I realized that I had a mothermayi_backup version in the modules directory; A copy I'd made when I first got just a little bit working. That must have been confusing Drupal. When I removed the directory, things immediately got better.
OK, now to figure out how to hook into the user register form.
Comment #9
hansfn commentedIt's a bit surprising, but even in Drupal 8 we have hook_form_alter. You can continue to use hook_form_user_register_form_alter :-)
Let us know if you need any more help, and if you need help, commit early and often.
Comment #11
dwillcox commentedProgress. The settings form works, and mothermayi_form_user_register_form_alter() works, adding the required fields in the user registration form.
But, I can't figure out how to get module-specific validations to run on form submission. My attempts using the D7 approach cause Drupal to get stuck in a loop. (At least that's what appears to happen.)
Any pointers would be appreciated,
Comment #12
dwillcox commentedOh, and while I'm thinking of it, drupalmoduleupgrader left a fair number of blocks around like this:
This implies that default values can be specified in one of those two files. I don't see any examples. What's the textbook way of setting default "out of the box" settings for config variables?
Comment #13
dwillcox commentedUnfortunately, the only reason I'm able to spend time on this now is because I'm home, laid up by a nasty flu. That means I'm only operating on about 30% of brain capacity.
Comment #14
dwillcox commentedShoot, and I just realized that I've been putting the wrong issue number in my commits.
Comment #15
hansfn commentedYou wrote "The settings form works", but using the code from Git gives a broken form. Forgotten to commit?
I have attached 3 small patches (which you might have fixed since it seems you have some code which hasn't committed):
Comment #16
dwillcox commentedTrue, I probably haven't committed the latest version. At least not the version that breaks.
But I think I figured out the problem with getting the validation function called. As small matter of a missing
use Drupal\Core\Form\FormStateInterface;work on this a bit more, then will commit. I'll also check your patches.
Comment #18
dwillcox commentedThanks for all of your hand-holding hansfn, you've been a big help.
I think this is sufficiently functional now to warrant an alpha release. There are a few cosmetic things to clean up, but I think this works.
One thing that's still unclear to me: How to provide initial, default values for settings. Can that be done in the settings or schema yaml? Or is that you'd do in module.install?
Now that this is working, I think I'll tackle datereminder. It's rather more complex, but now that I have some admittedly limited experience with D8 apis, that's sounding less daunting.
But not tonight.
Comment #19
dwillcox commentedComment #20
dwillcox commentedRats. There's still a problem with the settings menu. I get a fault in validate. Will deal with this tomorrow.
Comment #21
dwillcox commentedI think it boils down to one of my config settings actually being an array. (Value and html style.) Before, when the schema file was wrong, apparently Drupal allowed me to set just anything. But with an actual schema in place, it balks at storing an array when it expects a string.
So what's the textbook way of dealing with this?
Defining two separate settings? (ick)
Can you have "array" as a type in the schema?
Can you have something like:
mothermayi_secret_hint: {value: '', format: 'basic_html'}in module.settings.yml
Comment #22
hansfn commentedRead https://www.drupal.org/docs/8/api/configuration-api/configuration-schema... It seems you can use a mapping for arrays.
Default values are set by the values in config/install. The values are kept after uninstall which some times is annoying when developing.
Comment #24
hansfn commentedThe settings form still didn't display properly for me. I had to apply the attached patch. (Another patch is coming up.)
Comment #25
hansfn commentedAnd with this little patch validation works - my user registration form is protected :-)
PS! I think "array" is wrong the config stuff, but I haven't looked at that now.
Comment #27
dwillcox commentedThe validation patches all look good. I don't understand why you didn't see the form on user registration, though. Is it possible you didn't clear the cache?
The user registration form is cached. Which is a pain. I need to figure out how to deal with that, and have a separate open issue on that.
If you also use captcha on the user registration form, it handles disabling cache for that form. But Mother May I shouldn't depend on that.
I have another ticket open to deal with the caching, Hans, if you have any pointers on that, I'd appreciate it.
Comment #28
dwillcox commentedD7 had the concept of disabling a module (make it stop working, but keep everything around), and uninstalling it (clean out everything). Apparently D8 doesn't have that distinction, and "uninstall" is more like D7's "disable?"
Maybe the module.install should take care of cleaning out everything. That was the case in D7.
Comment #29
hansfn commentedI actually cleared the cache, uninstalled the module, and cleared the cache and then enabled the module again. I don't understand how the settings form could display for you without the changes in my patch.
I just tested. I was wrong. uninstall clears the configuration. It might have been a problem in the early D8 releases,
Comment #31
dwillcox commentedI actually cleared the cache, uninstalled the module, and cleared the cache and then enabled the module again. I don't understand how the settings form could display for you without the changes in my patch.
Very strange. It was working OK for me, though your fixes were for obvious bugs. Could it be that I have my PHP configuration set to be more forgiving of errors?
Cool. One less thing to worry about.
Well, if it works for you and for me, it must be good. :)
I do want to see if there's a better way to handle that one settings field other than "array," but that's not critical. Then there's disabling cache for the registration form.
Comment #32
dwillcox commentedMy attempt to replace the "array" with a mapping failed. Failure on install.
It was probably something I did wrong, but at this point, I'm going with "If it aint broke..."
Comment #33
hansfn commentedDo you mind committing the patch in comment 24 (for the settings form)? I need it.
I get one "Strict Standards" warning (which you don't get because of different PHP settings) and one fatal error "Invalid placeholder (!url) in string" which I'm surprised you don't get. Which version of Drupal 8 are you using?
Comment #35
dwillcox commentedSorry, I must have missed comment 24. I just committed that patch. (Had to do some hand massaging due to intervening changes. It looks right, though.)
Oh, look. If I look in the log, I see the error. Now I don't see it. I guess I should check that more often. I'm more used to things blowing completely up.
Thing, is, I don't see that description on the form. How would see that?
And I'm running Drupal 8.2.5. I realize there's an 8.2.6 now, but didn't want to risk chaos by doing a core upgrade in the middle of module development.
And I'll checkout the strict error.Looks like your patch addressed the strict error, too.
Comment #36
hansfn commentedAnother patch with various fixes related to submission of the settings form. (Obvious stuff.)
PS1! The complete site seems to hang if I make a specific choice on the settings form. Haven't tracked it down yet - maybe related to the empty field setting. Weird.
PS2! Remove the "mothermayi.info" file left over from D7.
Comment #37
dwillcox commentedRegarding clearing the user register form cache, some interesting discussion here: https://www.drupal.org/node/2851803
Comment #40
dwillcox commentedLet me know anything more you have about the settings issue. Does the hang happen when you do the setting form, or later when you do a user registration.
From what I'm seeing, if you don't clear all caches after changing settings, things can certainly go wrong; the form doesn't get updated, but the verification and submission methods don't know that. This business with caches is turning into a bigger deal than I thought.
I may need to add a settings form option to clear all caches. I assume there's an api for that.
Comment #41
hansfn commentedHappy news - I think I have fixed the form cache issue. (After you have confirmed you can update the forum post you linked to.) After applying the patch, you need to rebuild cache. After that the user registration form is rebuilt whenever any of the module settings are changed. I think the solution was quite nice, but I didn't find it documented anywhere ...
Comment #42
hansfn commentedI think the attached patch is a more correct config setup - switching from "array" to "mapping" (which is a documented type).
I wonder if the hanging is related to something else. I'm running the Drupal setup on my Windows laptop ...
PS1! When you manually applied my patch from comment 24 you added a typo - $form_State in stead of $form_state on line 155 of src\Form\MothermayiSettingsForm.php
PS2! You can remove the hook_variable_info implementation from mothermayi.module There is no such hook in D8. I guess this is defined in config/schema, isn't it?
Comment #44
dwillcox commentedOK, I think this one seriously qualifies as black magic. And it apparently covers the page cache as well, assuming that's what I was seeing.
I sort of see what's going on, but there's no way in heck that I'd have figured that out on my own.
Yes, this causes the form to be updated whenever the settings change. Good progress. All that remains now is to force the rebuild the first time around. Do you thing it would be too egregious to force a cache clear on module install? Or maybe the first time the settings are saved? I could add an option to the settings form that defaults to "yes" the first time, and "no" subsequently.
Comment #45
hansfn commentedI think you can safely force the first time rebuild when installing the module - through mothermayi_install(). I don't have any sample code. Check one of the core modules maybe if the API documentation isn't clear enough.
PS! Don't forget to fix the typo I mentioned above.
Comment #47
dwillcox commentedI agree, this is more correct. It's almost exactly what I tried earlier, but I had the settings.yml wrong, and wasn't up to dealing with it at the time.
I'll look at your there "PS's" now.
Comment #49
dwillcox commentedSigh. Why is it never simple? The "obvious" solution sounded like I should call
drupal_flush_all_caches()inmothermayi_install().But that resulted in:
Comment #51
dwillcox commentedOK, think I got the cache thing licked. Added a setting variable, initialized to true, to trigger cache flush the first time settings are saved. Setting is set to zero, to disable future flushes.
Comment #52
dwillcox commentedAbout done with the flu, so back to my day job tomorrow, meaning much less time to devote to this. It's been a highly valuable exercise.
Comment #53
dwillcox commentedI'll call this "Needs review" for now, though it's been an active collaboration getting to this point. There should be a beta release available shortly.
Comment #54
dwillcox commentedSo how do we get rid of the "it's not usable yet" on the project page?
Comment #55
hansfn commentedYou create a alpha or beta release and change the issue status for #2851027: [mothermayi] Mother May I to "Needs review" - ref https://www.drupal.org/project/contrib_tracker#statuses
Comment #56
dwillcox commentedMore magic! I am constantly amazed at the scale of this whole project.
Comment #57
dwillcox commentedComment #58
dwillcox commented