Needs work
Project:
Variable
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
9 Feb 2012 at 23:56 UTC
Updated:
8 Mar 2016 at 16:18 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
geek-merlinthought a bit about it and maybe the easiest way ist to add an entity definition for the variable table.
edit: of course we would need a numeric id for that...
edit: no, that's no good - a variable can have a default value although nothing is in the db.
Comment #2
geek-merlinupdate: variable.module provides tokens so we can do it that way.
so this is only about using data browser to access variable values which surely has minor prio or is wontfix.
Comment #3
fagoyep, also it would be great if the variable module would provide variables as "entity properties" via hook_entity_property_info(). There is a special 'site' key for such global data.
Comment #4
geek-merlinright. so moving this to variable module.
Comment #5
jose reyero commentedSounds interesting, where can we find that 'site' entity?
Comment #6
jose reyero commentedClosing, no follow up. Feel free to reopen.
Comment #7
tedbowI am attaching a patch that starts off this. It implenents hook_entity_property_info_alter
http://drupalcontrib.org/api/drupal/contributions!entity!entity.api.php/...
It would need a lot more work but at least works form showing the variable under "site" in the data browser
Basically it exposes the variables as metadata properties of the "site" entity.
The getter callback will need to be more dynamic and the will need 'type' of the properties based on the variable type key.
I have tested this for showing a message via a rule that displays a simple string variable('site_frontpage').
Comment #8
tedbowMeant to reopen
Comment #9
tedbowOk, I added the setter method to the metadata properties. This allows setting the variables through Rules.
I tested it by setting a string variable.
Comment #10
mitchell commentedWow. This is cool! tedbow++
I have a few questions:
* Should
variable_entity_property_info_altercheck if Entity is installed?* Would it be possible/desirable for site variables to be in a subsection as [site:variables], similar to [site:current-page]?
* Would it be possible to declare data types for these text and integer values, or would that be better to do separate from this wrapper?
I noticed a few of errors/unexpected behaviors:
*
Notice: Undefined index: description in variable_entity_property_info_alter() (line 810 of .../variable/variable.module).when adding a 'drupal_message' action, but it seemed to go away. It then reappeared, and I think 12x was the common pattern. (shown in screenshot)* Another error, that I was only able produce once, while setting [site:preprocess-css] was like 'Data value is required. \n Data parameter is not set.'
* When [site:preprocess-css] was set to 0, 'drupal_message' did not display anything.
Attached is a screenshot of this patch in action. Note: to make a screenshot that included the data selector dropdown, I had to do Alt+H (which opened another menu in the background) and then do print screen.
Comment #11
tedbowThanks
I don't think so becasue the hook is defined in Entity so it would also be enable if called
Yes I think that is good idea. The list gets very long.
This will need to be done. Basically we to have some translation from what "variable_build_info" returns and what "hook_entity_property_info_alter" expects with properties.
Right now i don't have time to get back to this. If someone else wants to tackle it I can help.
Comment #12
jose reyero commentedLooks great, I'll be committing it as soon as all these issues are fixed.
Some issues:
- The list of variables should be retrieved with: variable_get_info() instead of variable_build_info()
- Some of Variable module variable names are group names (like 'node_options_[node_type]'), these ones should be built with variable_build() and then check for $variable['children'].
- Typo in function name: variable_meTATdata_set_property(
- This function should be using variable_set_value(), to go through full variable API, instead of variable_set(), I guess
Comment #13
tedbowOk another try at this
I didn't do this. This is actually must harder than I thought. It works fine for view values but not for setting them. You get a error "Unable to set the data property xxxx as the parent data structure is not set. Rules expects the direct parent to be a entity of some sort I think. I similar problem is described here #1696594: Setting data to double field through rules.
[site:current-page] works because the properties underneath it are read-only.
If anyone wants to look into it the problem comes from EntityStructureWrapper->setproperty() in the entity.wrapper.inc.
The current method works it just causes a long list under "site:" in the data browser. There is going to be long list somewhere b/c of the number of variables.
I fixed the other issues in #12 above.
Marking as "needs review" to get feedback. But really it needs more work probably.
Comment #14
mitchell commentedThe error messages are fixed.
I'm still getting this unexpected behavior:
* When 'Aggregate and compress CSS files' is disabled, 'Show a system message' of [site:preprocess-css] does not display anything.
I believe the attached interdiff from #1540180: Add a property for user's default theme may help a bit.
> error "Unable to set the data property xxxx as the parent data structure is not set'.
AFAIK, the source of this error is a configuration element" which receives a data type different from what the plugin supports.
Rules' configurations are oriented in a nest / tree structure, and parent elements expose values through property chains. For example, the 'Entity has field' condition exposes a field's values to child actions in the configuration.
Comment #15
tedbow@mitchell
I think is expected. The value you are trying to display == 0. Because of the way drupal_set_message is coded "0" will not be displayed.
You can test this my making a rule with an action to display a message and just put 0 (zero) in. It will not be displayed. also the code:
drupal_set_message(0);Will also not display.
Comment #16
tedbow@mitchell do have an idea how to solve the issue from #13/#14?
Comment #17
mitchell commentedHmm, I think a good workaround would be to declare a new site-wide ‘variable’ faux-entity.
Comment #18
geek-merlinI think the current "spirit" of rules data would be a "variable" property of "site, making it [site:variable:foobar]
Comment #19
eileenmcnaughton commentedi just wanted to link this across
http://drupal.org/node/812058#comment-6536478
From what I can see it doesn't allow you to use tokens in the comparison operator (which is how I hoped to use it - Data (Integer) is one of [variable:myselecteditems]) - however, it does indicate the syntax rules module is following ie.
[variable:value]
From where I am I think I am hitting 2 short-comings - 1) Rules is now supporting tokens - but not for the list type & 2 it isn't supporting them for data comparison. (I'm planning on backing off my approach for now - I was just trying to find a way to let people select some criteria outside the rule feature I'm setting up)
Comment #20
turion commentedIs this now being worked currently?
Comment #21
geek-merlin