
The "Context States" 7.x module allows administrators to define "States" (setting variables) that can then be used by Context and set by editors.
It provides two permissions to "Define States" and "Edit States" that control access to two Management pages (/admin/structure/states and /admin/structure/states/define). The latter allows an administrator to define states, one per line, in a textarea. The former then can mark those states as active using checkboxes.
The States are provided as a Context condition plugin so that an administrator can define contexts based on the presence/absence of those States.
There is an install task to clear cache (so States option will appear in Context) and an uninstall task to remove variables on uninstall.
Project Page: https://drupal.org/sandbox/evanmwillhite/2135843
Git clone: --branch 7.x-1.x evanmwillhite@git.drupal.org:sandbox/evanmwillhite/2135843.git context_states
Reviews of other projects:
https://drupal.org/node/2135793#comment-8185319
https://drupal.org/comment/8185591#comment-8185591
https://drupal.org/comment/8185635#comment-8185635
Comments
Comment #1
PA robot CreditAttribution: PA robot commentedThere are some errors reported by automated review tools, did you already check them? See http://pareview.sh/pareview/httpgitdrupalorgsandboxevanmwillhite2135843git
We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)
Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).
I'm a robot and this is an automated message from Project Applications Scraper.
Comment #2
evanmwillhite CreditAttribution: evanmwillhite commentedThanks for your patience with a first-timer. I've gone through and reviewed the automated feedback and made changes accordingly. The only issues left from that feedback refer to the context_states_context_condition_states.inc where I follow the Context module's conventions as opposed to what appears to be best practice in terms of class naming.
Comment #3
idebr CreditAttribution: idebr commentedHi Evan,
Great looking module, just a few pointers before it is ready for release:
Also, you are correct in not sweating the notices from the automated tests, since you are following the Context API correctly
Comment #4
evanmwillhite CreditAttribution: evanmwillhite commentedThanks so much for the positive feedback and great recommendations. I've implemented them all and re-run the automated test. The only one I put back in was clearing the cache in hook_install(). It's the only way I can get the Context condition to show up unless you happen to know another approach. Thanks!
Comment #5
idebr CreditAttribution: idebr commentedHi Evan,
Your changes look great! I have just a few more nitpicks, then you are good to go :)
You can put the administration forms in the same file, the most important thing is they are not in the .module. Sorry I didn't make that clear in my previous comment, my bad! By convention, this file is often called [modulename].admin.inc, so in your case it would be context_states.admin.inc
context_states_form.inc:8 should say 'Implements hook_form().'
context_states_define_states_form:8 should say 'Implements hook_form().'
system_settings_form($form) already saves each field as a variable in its submit function, so in context_states_define_states_submit() you create a duplicate variable. You now have 'context_states_defined_states' as well as 'defined_states' in your variable table. You can rename the form field from $form['defined_states'] to $form['context_states_defined_states'] and it will save automatically into a variable. For more information on this, check out system_settings_form() and system_settings_form_submit()
Comment #6
evanmwillhite CreditAttribution: evanmwillhite commentedNo problem at all, and thanks so much for the encouraging assistance! I believe I have implemented those changes correctly, although I'd welcome a second look. The automated review doesn't seem to like the "Implements hook_form [x]" style. Thanks again!
Comment #7
idebr CreditAttribution: idebr commentedAh yes, I see what you mean. In the notification e-mail for changes in the issue, links are appended with a footnote and I added a link to the hook_form() documentation. You can replace 'Implements hook_form [1].' with 'Implements hook_form().' like you did correctly for hook_menu() in context_states.module:11. The function docblock lets other developers know what hook you implemented, so they can look up the documentation.
A last remark about the field name you changed in context_states_define_states_form(). Since you changed the field name to 'context_states_defined_states', it gets saved automatically to a variable of the same name by the system_settings_form(form) callback. This means that you can now safely remove the context_states_define_states_submit() function in context_states.admin.inc:28 and the variable will still be updated.
Comment #8
evanmwillhite CreditAttribution: evanmwillhite commentedOk, thanks again. I've changed the hook_form() comments accordingly. Regarding the change in the submit handler for context_states_define_states_form(), I wasn't able to remove the submit function entirely, but I was able to remove the variable_set function within it.
Comment #9
idebr CreditAttribution: idebr commentedGreat work! I am not sure on the procedure on who can set the status to 'Reviewed and tested by the community', but I am sure one of the moderators will correct me if I am wrong :)
You can safely remove
function context_states_define_states_submit()
on context_states.admin.inc:28 once you remove the additional submit callback$form['#submit'][] = 'context_states_define_states_submit';
on context_states.admin.inc:20Best of luck with your submission :)
Comment #10
Bogdan1988 CreditAttribution: Bogdan1988 commentedHi evanmwillhite, thank you for nice code.
Here is my suggestions after manual review:
1)In this file context_states.admin.inc as doc you are using hook_form. In fact hook_form is only for modules that define a content type. To put right docs, please look here https://drupal.org/node/1354#forms;
2)also line 60 in the file above
'#markup' => t('No states have been defined'),
It seems to me that it would be better to put tag out of t() function;
3) Your submit handler is empty context_states_define_states_form(), Maybe it would be better not to declare it at all;
4) In hook_install you could use cache_clear_all('*', 'cache', TRUE);
5) In hook_uninstall you could use
$nodes = db_delete('variable')
->condition('name', db_like('context_states_states_') . '%', 'LIKE')
->condition('name', 'context_states_defined_states')
->execute();
That's all thank you!
Comment #11
evanmwillhite CreditAttribution: evanmwillhite commentedThanks to both of you! I have removed
function context_states_define_states_submit()
and$form['#submit'][] = 'context_states_define_states_submit';
per #9. Thanks for explaining that in more detail, that's great info.Also, I have edited my hook_form comments to better suit the requested documentation and changed the hook_install and hook_uninstall functions to the recommendations. The only one I tweaked was hook_uninstall as it wasn't removing 'context_states_defined_states' so I separated that back out into a variable_del() function and they both work great now. Also ran everything through the automated test and it checks out.
Only one I didn't follow was #2 regarding the markup part. I'd welcome a bit more clarity on that.
Thank you both again very much!
Comment #12
idebr CreditAttribution: idebr commented#10:2 refers to this code on context_states.admin.inc:58
The t() function typically only prints plain text.
To help site administrators find the right course of action, I would suggest changing it to:
Comment #13
evanmwillhite CreditAttribution: evanmwillhite commentedExcellent, thanks for that clarity, and I like the check for permission and extra help link. Made the change and everything looks great. Cheers!
Comment #14
evanmwillhite CreditAttribution: evanmwillhite commentedComment #15
evanmwillhite CreditAttribution: evanmwillhite commentedComment #16
evanmwillhite CreditAttribution: evanmwillhite commentedComment #17
evanmwillhite CreditAttribution: evanmwillhite commentedComment #18
klausimanual review:
But otherwise looks good to me, so ...
Thanks for your contribution, evanmwillhite!
I updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.
Here are some recommended readings to help with excellent maintainership:
You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!
Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
Thanks to the dedicated reviewer(s) as well.