name: sitevars
version: 7.x-1.0
sandbox: https://drupal.org/sandbox/kris-o3/1833646
description:
Edit a key-value store, accessible from Configuration > System > Site variables.
Specify keys as a comma-separated list, then a value for each key. This is stored in {variable} by the name sitevars_keys. Then specify a value for each key, which is stored with the prefix sitevar_ (this establishes a namespace distinct from existing variables). Empty strings will not be stored in the database; deletion is automatic.
The function sitevars_get() is provided for convenient retrieval of values, without the need to specify the sitevar_ prefix when calling variable_get(). Pass it a string to retrieve one variable, an array of strings to retrieve several; call it with no arguments to obtain your entire key-value store.
Comments
Comment #1
wolvern commentedHello kris-o3,
Firstly, you should sort out the line breaks in your files, the autoreview script sees most of the code in a single line: http://ventral.org/pareview/httpgitdrupalorgsandboxkris-o31833646git
After that, note that you are using a somewhat different coding standard from what is expected in Drupal code: http://drupal.org/coding-standards.
You've completely forgotten to include any inline comments for your code. Check out here: http://drupal.org/node/161085.
Although, I think, the main question that should be discussed is the need for such a module in the first place. I can hardly imagine a site builder who would need a variable to be used in code, but who wouldn't know how (or would choose not) to set one using variable_set(). But I could be missing something. Could you describe a situation where this module would come in handy?
Comment #2
ankitchauhan commentedComment #3
kris-o3 commentedto be fair, i installed and ran the Coder module extensively prior to adding/committing my module for review, so beyond linebreaks being LF (os x/linux) instead of CRLF (windows) and the lack of comments explaining the functions (of which there are only a few)... what else did i do "wrong?"
per the more important question as to what use case this module serves... while it's true that there are individual modules to manage, say, api keys or site id's for google analytics, another for mailchimp, still another for salesforce, etc. etc. ad nauseum, i came up empty looking for a module that serves my own needs for a simple interface to define some variables i could call upon in my custom themes/templates.
i had recently done something similar using a content type that contained a field collection of zero to many name/value pairs, and while this worked, felt just awful. storing configuration in content. ugly.
so i made this module.
it's true that a developer could, in their template.php file, use variable_get and variable_set as needed, but if a nontechnical person ever needed to update say, again, an api key for some 3rd party service, that person could do so in a simple form rather than digging into code or opening a trouble ticket requiring billable time w/ a developer.
so there's the use case.
i'm actually still working on this, so if the linefeeds are a Major issue i can convert to CRLF and i will indeed comment my code so that anyone who chooses to extend this module will know what's going on... in addition i'm tweaking things so it stores all key/value pairs in a serialized array in a single variable, for performance and efficiency sake.
Comment #4
smiletrl commentedHi kris-o3,
Agreed with saulelis, code in this module is using a different standards. And I think we could add some explaination for each function, like
This part
'page callback' => "sitevars_settings_callback",, if all the page callback does is to render a form. I think using drupal_get_form as page callback and form id as 'page argument' would be a better choice.As for the use case of this module, I agree that storing configuration in content is not a good practice. Thing is, what does u what to do with ' many name/value pairs'? The first thing coming to my mind is to use a select list field in content type. And if you want to collect data from user, you could use a form. For nontechnical person, if using variable_get and variable_set is difficult, should be using sitevars_get() much easier? Anyway, only a suggestion:)
Comment #5
kris-o3 commented"I think using drupal_get_form as page callback and form id as 'page argument' would be a better choice"
tried that, didn't work. i was going by what i was taught in an Acquia-approved module development course... while possibly unnecessary is it really a 'problem' to do it this way?
again to the more important question of use-case...
would you not agree that, at times, a site administrator and front-end theme developer are Often not the same person?
the idea is simply to provide an interface to store/retrieve some variables that are referenced in the front-end theme using variable_get or the provided utility function sitevars_get... once the site is deployed/launched, someone other than the front-end theme developer would be able to easily update any of the variables, or add a new one and ask their front-end dev to display it in the theme somewhere.
i imagine this is why things like email and site slogan exist in the "Site information" form, yes? the idea here is precisely the same.
Comment #6
smiletrl commentedHi,
If you put it like email and site slogan, then I'm okay with that:)
For page callback, it's just a personal practice. It's not a 'problem' to do this anyway. But, could u paste your code for this part? I'm just curious that this doesn't work for you.
Also, there's function of preg_replace in .module. Use preg_replace_callback() instead. See https://drupal.org/node/750148
Comment #7
kris-o3 commentedper that post, i'm not using the /e flag, so preg_replace is fine.
Comment #8
kris-o3 commentednow version 7.x-1.1
Comment #9
kris-o3 commentednow version 7.x-1.2
added ability to filter list of variables by a prefix.
Comment #10
kris-o3 commentedchanging status from 'needs work' to 'needs review'
Comment #11
stborchertBack to "needs work" since there are several task to do:
You can find the results of the automated report at http://ventral.org/pareview/httpgitdrupalorgsandboxkris-o31833646git.
Comment #12
kris-o3 commented"You should really be working in a version specific branch."
- even for a project that hasn't yet made it past its 1st review to become a full-fledged project?
"You are using Windows (?) line endings"
- that's funny because i got a complaint on a different project that i was using Unix line endings and to please use CRLF.
as for the last 3 bullets in Code, noted and will resolve.
Comment #13
kris-o3 commentedhttp://git.drupal.org/sandbox/kris-o3/1833646.git
http://ventral.org/pareview/httpgitdrupalorgsandboxkris-o31833646git
Review of the 7.x-1.x branch:
(now completely blank. clean report.)
Comment #14
kris-o3 commentedre-committed after a final review by both Coder and PAReview.sh
Comment #15
ain commentedInteresting idea for a module.
Code review
Automatic
No errors, all clear.
Manual
Everything seems in order and
check_plain()is used to evaluate user data entry. Uninstall cleans up nicely.Testing
Testing was a success, module does everything that it says to do.
Recommendations
NB! Make sure to review 3 other modules and tag this application with PAReview: review bonus in order to get it resolved for good. Check the Review bonus for more info. Otherwise I think it's RTBC.
Comment #16
kris-o3 commentedi might have guessed there was a standard for changelog, my mistake honestly. will edit asap.
Comment #17
kris-o3 commentedchangelog updated.
Comment #18
jthorson commentedOne of the goals of this review process is to help develop familiarity with and proper use of the Drupal APIs; so while the code may work, reviewers are always going to point out the recommended or best practice approach. Encouraging 'one way' to do things helps ensure consistency between contrib modules, which is a benefit to end users.
Similar to the 'proper use of Drupal APIs' comment above, we like to use this review process to demonstrate familiarity with the branch & tag naming patterns.
I'd be interested where you got this complaint ... the standard is definately Unix-style line endings in the drupal.org repositories.
Comment #19
jthorson commentedRather than using $_SESSION['sitevars_filter'], I'd suggest storing the preference in the $user object (as described in http://www.braahm.be/node/7).
t(": <em>@filter</em>", array('@filter' => $filter)):As per the documentation at http://api.drupal.org/api/drupal/includes!bootstrap.inc/function/format_..., You can use %filter here instead of @filter, which will include the
<em>tags for you.t("@spacewith prefix: <em>@filter</em>",I'm curious about the @space variable here ... simply including a space at the beginning of the string would be just as effective, and would be more straight forward for translators.
t("Are you sure you want to delete @plural?", array('@plural' => (count($names) != 1 ? "these variables" : "this variable"))),I think the context of the 'this/these variables' portion of this string is lost for translators ... use format_plural() instead of t() here. See http://api.drupal.org/api/drupal/includes!common.inc/function/format_plu...
t("@plural !list deleted.",Same concern (providing context to translators). Use format_plural().
sitevars_formI'd recommend adding a sitevars_add_validate() routine (and the equivalent sitevars_filter_validate()), to alert the user when they've supplied non-allowed characters, rather than simply stripping them from the input.
Comment #20
jthorson commentedNone of the above are showstoppers, so ...
Thanks for your contribution, kris-o3!
I updated your account to let you 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 get 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.
Comment #21
kris-o3 commentedhuh! format_plural... there's so much to drupal, reading lists of functions is like reading the dictionary :)
will look into that for a future update...
definitely also didn't know about storing additional 'temporary' info in $user... that's pretty cool.
the form description Does indicate which characters are considered valid for a variable name...
but yes, better UX would be to both indicate as well as validate.
hooray! it's a project! thanks, all. i did actually learn a lot during the review process.
Comment #22
kris-o3 commentedhmm, i followed the instructions to tag 7.x-1.x as 1.0 and created a release, but still not showing up in Downloads at /project/sitevars
git status
# On branch 7.x-1.x
nothing to commit, working directory clean
git checkout 7.x-1.x
Already on '7.x-1.x'
git tag 7.x-1.0
fatal: tag '7.x-1.0' already exists
git push origin tag 7.x-1.0
kris-o3@git.drupal.org's password:
Everything up-to-date
Comment #23
kris-o3 commented.zip finally now appearing. SWEET.
Comment #24
jthorson commentedPublishing of releases takes up to 17 minutes after 'go' ... and we've had some instances of the publishing script hanging, and having to be restarted in the past few weeks.
Comment #25
jthorson commentedAnother implication to using $_SESSION for storage ... Drupal 7 will disable anonymous page caching if a session exists, which can cause performance issues on large/busy sites.
Comment #26
kris-o3 commentedi guess drupal core does it entirely wrong, huh...
line 139 of modules/node/node.admin.inc, in function node_filter_form
$session = isset($_SESSION['node_overview_filter']) ? $_SESSION['node_overview_filter'] : array();
and line 225, in function node_filter_form_submit
$_SESSION['node_overview_filter'][] = array($filter, $form_state['values'][$filter]);
this is actually where i got the idea to do it this way...
from the CORE NODE MODULE /admin/content form.
Comment #27
jthorson commentedIn the case you reference, the pages are on the /admin/% path. By their nature, these paths are not made available to anonymous users, and so the implication of 'disabling page caching for anonymous users' does not apply.
So whether it becomes a concern for sitevars depends on the use case ... as long as nothing is written to $_SESSION for the 'anonymous' role, then this can be avoided. I just wanted to point out the potential for an issue when using $_SESSION, especially given that alternatives such as storage within $user->data exist.
Comment #28
kris-o3 commentedthat is correct. it is only used to persist what is typed in 'filter by prefix' on the administration/config form for sitevars.
as seen here: http://drupal.org/files/project-images/sitevars.png