Closed (fixed)
Project:
Scheduler
Version:
8.x-1.x-dev
Component:
Code
Priority:
Critical
Category:
Task
Assigned:
Issue tags:
Reporter:
Created:
2 Feb 2015 at 12:18 UTC
Updated:
18 Nov 2015 at 20:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
stred commentedComment #2
stred commentedscheduler.test remains
Comment #3
legovaerApplied the changes to scheduler.test and modified some parts of #2.
Best practice here is avoiding instantiating config objects multiple times within the same function, as this is a performance drain. The following code unnecessarily instantiates the config object 'scheduler.settings' twice.
A better solution is to instantiate the config object once, save it into a variable, and work with that variable for the rest of your code scope.
(Source: Simple Configuration API --> Best Practices)
Comment #4
legovaerComment #5
pfrenssenChanges look good, but we should wait a bit with this until we have converted the node type specific settings to use the ThirdPartySettingsInterface. If we use this class then we don't have to deal with the config directly.
Will postpone this for now.
Comment #6
pfrenssenMarked #2603062: ADMIN->Save Scheduler config finished by error as a duplicate of this issue. The node type specific settings have already been converted so this can be unpostponed. Also raising the priority since this prevents the saving of the administration form.
Comment #7
jonathan1055 commentedI downloaded the Scheduler 8.x dev from 14th Oct to test the patch in #3, but it no longer applies:
Not surprising really, as you've all been doing great work and since 9th Feb the code base will have changed considerably.
Comment #8
jonathan1055 commentedThe failures were only in the .test file, so I could test the scheduler admin settings. The date format is saved ok. But if I tick the 'date only' option and save, the value is not saved. The watchdog has
Removing the submit handler line 82
stops the error being produced, but the option and default time are not ssaved.
On the 'Lightweight cron' tab the log checkbox and cron access key are saved correctly.
So it seems to be just the 'date only' fieldset which is not catered for yet.
Just to try, I moved the checkbox out of the fieldset into a stand-alone item and it was saved correctly. So there must be a new way to cater for fields inside fieldsets. Hope that helps.
Comment #9
jonathan1055 commentedMaybe in function submitForm we need to traverse to the lower level within the fieldset?
Does Element::children return only the immediate children, or all the lowest level form items? I have limited internet search capacity right now, but I expect this is simple to fix.
Comment #10
joshi.rohit100Comment #11
jonathan1055 commentedThanks to the power of searching drupal core code, I think it is simply a case of naming the variables directly:
The above works. But do we leave the loop in and just do the fieldset ones as extra? or should we do this explicitly for each variable (there are not many). I would favour the explicit lines, as is done in core, as it makes it easier to read.
Comment #12
jonathan1055 commentedOops, sorry joshi.rohit100 I did not see you had assigned this. Please go ahead, you are welcome to work on it :-)
Comment #13
joshi.rohit100It seems like tests are not properly implemented (or wrongly implemented), so I haven't changed those. I think, it will be good to have follow up to correct the test cases.
Thoughts ?
Comment #15
jonathan1055 commentedHi joshi.rohit100,
Your change to instantiate the config object once at the top is good, thanks for doing that. Some points to note:
Regarding the tests, yes there is already a separate issue #2594615: Automated testing in 8.x [meta] to get them running properly. However, that should not stop us making the variable_set() changes to the .test files within this issue, even if the tests do not run those code changes need to be made anyway in preparation.
Thanks,
Jonathan
Comment #16
joshi.rohit100Comment #17
legovaerComment #18
kaushalkishorejaiswal commentedHi jonathan1055,
I have made the changes which you have mentioned. Kindly review it.
Comment #19
legovaerThe typo & submit handler have been removed. The
config->save()has been removed as well.Instead of using a foreach, I decided to go for the line-per-line approach in order to set the values for the fieldset. The foreach loop we used previously was also storing stuff inside our config we really don't want to have in there (E.g. form_id, ...).
The issue you had that values weren't saved while submitting the form was because we didn't save the values from the form elements inside the fieldset. I've tested this patch and my values are getting stored now.
I also udpated the .test files as you requested.
Comment #21
jonathan1055 commentedNice work, thanks for this.
Changes to test files are now being handled in #2594615: Automated testing in 8.x [meta] on a separate git branch, and the variable_get() changes are being handled in #2418523: Replace variable_get() with config. However, the other changes I think look good. If you could re-roll the patch without the .test and variable_get() changes it will be easier to make a final check, before committing the code.
Comment #22
jonathan1055 commentedJust spotted that the config->set of the main date format is missing. If you want me to re-roll the patch, say so, but as it is assigned to you it's fair to let you do it.
Comment #23
legovaerRe-rolled the patch and fixed #21 and #22
One minor change I did: I've removed the line where we set the variable $config because we're only using that variable once.
Comment #25
joshi.rohit100I guess patch is missing few things from #6
Comment #26
legovaerJoshi.rohit100 can you be a bit more specific?
Comment #27
joshi.rohit100In the buildForm (), initialising config object once.
I am not sure if it comes under variable_get() issue.
Comment #28
legovaerjoshi.rohit100, I'm not initializing the $config object in the buildForm() method?
The only thing I forgot was removing the submit handler from the form. This is done in the attached patch.
Comment #29
joshi.rohit100i think this should not be removed as you see we are just creating new instance every time by \Drupal::service()
Comment #30
legovaerEven if we don't remove it, we're not creating a new instance.
ConfigFormBaseTraitcomes with aconfig()method which we're using here. Calling this method will retrieve a configuration object.Also, the code isn't completely removed. I just made the code easier to read. Why should we create a variable which we're only using once? Instead of:
I'm doing:
Comment #31
joshi.rohit100I agree with your point that we have config() method in trait that we can use instead of creating new variable.
But
We are using \Drupal::config() three times in the buildForm method and I think, that can help there.
Comment #32
legovaerOk, now I finally got your point. Sorry, I blame Monday! ;-)
Comment #33
joshi.rohit100use $this->config('config_name')
Comment #34
legovaerDone #33!
Comment #35
jonathan1055 commentedLegovaer,
Thanks for re-rolling the patch - it seems to have been a bit of a fuss. The part of the patch in 21 for this specific file was almost perfect, so I'm not sure why you did not start with that patch (removing the sections for the other files) then just make your additional changes on top. You've ended up missing then re-doing quite a few of the changes already accepted, so just offering a little suggestion to save yourself time next time :-)
Also I spotted a typo where you set
->set('date_foramt', $format), and you missed out->set('default_time', $form_state->getValue('default_time'))so I am guessing you did not actually try out your changes and test them to see if they worked. Until we get the automated tests running manual testing is vital ;-)joshi.rohit100
Thanks very much for your reviewing and guidance. Nice work.
Here's a patch with the two typos fixed, and an interdiff to show what the work was. I noticed that
$form_state->getValue('default_time')works so is there any reason/benefit to also use [ and ] inside the getValue, as done in$form_state->getValue(['allow_date_only']). Both formats seem to work.When we've answered the above, and if you are both happy with this, I will commit it, then we can unblock #2418523: Replace variable_get() with config
Comment #37
legovaerJonathan,
You're 100% right. I made a mess with all my re-patching. I'm still getting used to the "patch" way-of-working. It would be so much nicer to have branches!
The patch in #35 looks OK to me.
Comment #39
joshi.rohit100Fixed !
Comment #40
jonathan1055 commentedThank you everyone. That was my first commit to 8.x :-)
Marking this fixed, but if Pieter reviews our work and would like anything changed, I'm happy to do that. It's good to get this fixed, then we can move on to the other issues being blocked by it.
Jonathan
Comment #41
pfrenssenIt's looking great, thanks everyone!