This module allows for administrators to specify a set of key/value pairs for use in node bodies.
The key/value pairs are specified in an easy-to-use administration interface. This module is geared toward larger sites that have lots of little data around the site that gets changed often. With this module, you can put a “key” into node bodies such as “~name_of_president~” and when the node is loaded, the key is replaced by the value, which would be “Barack Obama”. When President Obama is no longer president, you would simply replace his name with the next president’s name in one place, and it would get changed throughout the site.
Dependencies
- CKEditor module or Wysiwyg module (only TinyMCE as of now).
Differences
It is different from Wysiwyg template plugin because it inserts the variable key into the node body, and the value of the variable is determined when the node is loaded by the user. This way, you can change the value of the variable any time without having to worry about updating all the pages this variable is used in.
Link to project URL
http://drupal.org/sandbox/dwieeb/1294972
Git clone command
git clone --branch 7.x-1.x dwieeb@git.drupal.org:sandbox/dwieeb/1294972.git datadictionary
This module is only for Drupal 7+
Comments
Comment #1
sreynen commentedHi dwieeb,
This sounds a lot like an existing project: http://drupal.org/project/wysiwyg_template Have you tried that? It would be useful to explain differences in the project description.
Comment #2
dwieeb commentedUpdated! Differences section added.
Comment #3
dwieeb commentedForgot to change it back to "needs review".
Comment #4
klausi* README.txt ist missing
* Git release branch is missing, see http://drupal.org/node/1015226
* "Implementation of hook_menu()" should be "Implements hook_menu().", see http://drupal.org/node/1354#hookimpl
* Indentation should be always 2 spaces, not 3, see http://drupal.org/node/318#indenting
* you should run the coder module to check your code style: http://drupal.org/project/coder
Comment #5
dwieeb commentedThanks for the instructions. I believe everything is up to snuff now.
Comment #6
klausi* do not include LICENSE.txt, this added by drupal.org packaging automatically.
* "foreach ( $variables as $key => $value )" there should be no spaces after '(' and before ')'. Also for the if statements in your code.
* admin_main.js: indentation should also be 2 spaces, also for the other javascript files
Comment #7
dwieeb commentedHow about now?
Comment #8
klausiNot sure about all the markup in the form, if it should be in a theme function or a template ... leaving this for another reviewer to check.
Comment #8.0
klausiAdding section headers. Adding deps and diffs section
Comment #9
minoroffense commentedI agree, the form should use theme('table') to generate the markup. Otherwise admin themes won't be able to control the table display.
- Use theme('table") for the admin form theme_table
- Move CSS for the admin into a file. That way themers can override them if need be.
- Storing all the key/value pairs in one large variable in the variables table seems like it may cause some issues later on. Especially if you reach hundreds or thousands of keys or lots of very long keys (you may reach the mysql packet size limit on a larger dictionaries). I would suggest creating a table of key/value pairs along with cache system integration. May be slightly slower for smaller dictionaries but will save you on larger ones.
As a side note, had you considered using the Token system along with the Token Filter module?
Comment #10
sreynen commentedTables in forms are messy. I've done them similar to how dwieeb did them here, putting the table markup in #markup, #prefix, and #suffix. I've never seen any complaints about this approach. It's is relatively easy to read and can be changed with a form alter function, which themes can do now in D7.
Core does something different in places like the user permissions table, but I haven't been able to figure out how that gets from the abstract form object to the eventual HTML table output. We don't seem to have any community initiative to document and advocate the approach core takes, so I think it's okay if modules like this take the more obvious approach.
I do think you should remove the inline style in the form markup, and apply style with classes and separate CSS files instead. Separating structure and design makes it easier to alter both independently. Also, unless you have a good reason to use double quotes, you should wrap markup in single quotes. Single quotes make double quotes easier to read (since you don't have to escape them with \) and also executes slightly faster.
Everything I've mentioned changing here is pretty minor, so I'm moving this to RTBC.
Comment #11
dwieeb commented@minorOffense
- Moved CSS in the admin CSS file. Thanks
- Revamped the storage method for variables. Thanks
- I hadn't looked into Token Filter, but it looks like in order to add custom tokens to the Token system, the user must implement some semi-complicated hook functions, unless I'm misinterpreting. Data Dictionary provides a simple interface for site administrators to manage their variables as well as buttons for users to insert the variables into their wysiwyg editor.
@sreynen
- That's what I figured... the table is an integrate part of the form, which is why I used the form #markup, #prefix, #suffix.
- You're right about the single quotes. I was using double quotes out of habit. Thanks
Changing it back to needs review because of the storage method overhaul.
Comment #12
sreynen commented#10 was cross-posted with #9. I didn't intend to jump from needs work to RTBC. So needs review is good.
Comment #13
klausiOtherwise I think this is nearly ready.
Comment #14
dwieeb commentedOkay, updated. I have two warnings from Coder about line 36 and 51 saying I should translate and/or check_plain the $message variable. But in this case it would be unnecessary because it's just markup and an Exception message. Should I ignore these warnings?
If not, it's ready for review.
Comment #15
klausiThere is a security vulnerability in datadictionary_node_view() on line 461. You are embedding $value without sanitizing the input. I was able to exploit that by using a value of
<script>alert('XSS');</script>in a body field that was set to have a plain text filter.You must respect the text format setting of the body field, currently you are ignoring it. I don't think that hook_node_view() is ideal because it looks like the body field content is already rendered there. Maybe another hook might be an option, because then you could inject your values before text formats are applied.
Automatic review:
Review of the 7.x-1.x branch:
This automated report was generated with PAReview.sh, your friendly project application review script. Please report any bugs to klausi.
Comment #16
klausitiny_mce_popup.js: appears to be 3rd party code. 3rd party code is not generally allowed on Drupal.org and should be deleted. This policy is described in the getting involved handbook. It also appears in the terms and conditions you agreed to when you signed up for Git access, which you may want to re-read, to be sure you're not violating other terms. The Libraries API module is a recommended method for adding 3rd party dependencies without directly including the code on Drupal.org.
Comment #17
dwieeb commentedOkay, I've fixed the security vulnerability and the other problems coder gave, now I'm looking into a better way to replace variables in node bodies with their values. Perhaps hook_filter_info()?
About tiny_mce_popup.js: I modeled the TinyMCE plugin after the TinyMCE plugin in Footnotes, which also uses tiny_mce_popup.js. I assumed since it was approved there, I could use it in my module as well.
Comment #18
dwieeb commentedI looked into hook_filter_info(), but that only filters text when the node is saved. I need to filter text when the node is loaded (viewed). That way, if a value is changed, it actually gets changed in the nodes when they are viewed. I can make hook_node_view() work with text formats, but it's going to be ugly. If there's a foreseeable better way to proceed, please advise.
Also I need advice for tiny_mce_popup.js.
I guess I'll just mark this as "needs review."
Comment #19
klausiComment #20
klausiHm, I really think you should implement hook_filter_info() and others that belong to that. No, that does not filter on save, but on output. I just reviewed Multicolumn http://drupal.org/node/1181988/ which implements something similar very clearly.
Comment #21
dwieeb commentedAh, I see. Just set cache to FALSE and it applies the filter when the node is loaded. Thanks.
Okay, besides a bug with the filter and the CKEditor module (see here, waiting on a response from CKEditor module maintainers), it's ready for review again.
Comment #22
dave reidJust wanted to point out that this is what the http://drupal.org/project/token_custom module is for as well. It may be worth pointing on on this project's page that Token Filter + Custom Tokens would be an alternative to this module.
Comment #23
dwieeb commented@Dave Reid: That would work, but the user would still need to know basic PHP skills. But, along with Token Insert, it basically renders this module useless. Maybe I should just work with the maintainer of Custom Tokens to allow for more flexibility instead of only offering PHP code.
Comment #24
doitDave commentedIt was my first thought as well that your module's idea would be better implemented as some kind of add-on for tokens. Not only would that seem better to me in the sense of global module consistency, also does it feel uncomfortable to have to many proprietary token/placeholder styles. The latter is just a nebulous personal feeling of course, but IMO you should really consider hooking into the token stuff.
Besides that, I really like your idea and without much thinking I could find a lot of points in my own sites where such a function would make big sense.
Comment #25
beanluc commenteddwieeb, what are your intentions? Should this remain in a "needs review" status, or, do you intend to postpone this until you form some plan with the Custom Tokens maintainers?
Comment #26
klausiComment #27
avpadernoThere have not been replies in the past months.
Comment #27.0
avpadernochanging to dev brance