Needs work
Project:
Patterns
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
9 Jul 2009 at 02:35 UTC
Updated:
28 Sep 2010 at 17:26 UTC
Jump to comment: Most recent file
Comments
Comment #1
ChrisBryant commentedThis is definitely a feature that we've been wanting to add for a good while now! Thanks for sharing your patch as well.
The direction that some if this goes may be influenced by some of the work being done in the Configuration Framework module. It's goal is to make this type of feature much easier.
Sarva and/or Vaish can provide more info about that, but if you haven't had a peek at that yet, please have a look.
Thanks again for sharing and I hope we can get this included asap!
Comment #2
johnbarclay commentedSounds good. I'll keep an eye on the configuration framework before I add any more of these "generate" widgets. Thanks again for your work on this module and presenting at Drupalcon.
Comment #3
paulap commentedHi,
I use the latest dev version of patterns. I patched the module (cd to patterns module directory, patch < ....patch.
The patch created one file (patterns.generate.inc) and changed the menu-entries in the module file.
But nothing happend in the browser if i refresh the patterns page.
PS: i use drupal 6.13 and a lot of other modules...
Please help
wr
Gerald aka paulap
Comment #4
sarvab commentedIf you have the module admin_menu, you could go to admin/settings/admin_menu and click the Wipe and Rebuild at the bottom. If not, maybe try changing a menu item anywhere admin/build/menu.
It can be a pain to have drupal recognize menu changes sometimes ;)
Comment #5
paulap commentedComment #6
sarvab commentedComment #7
sarvab commentedComment #8
sarvab commentedComment #9
johnbarclay commentedThis is the current version of this patch. I've been using it for a while and made minor changes and wanted to diff it against the current patterns module.
Comment #10
joestewart commentedThe generate patch is working pretty well. A big help, thanks.
It doesn't handle variable arrays yet.
How should variables that don't contain strings ( integers only) as array keys be built? There is a great example at http://drupal.org/node/409180 of how to represent variable arrays with string keys.
Comment #11
johnbarclay commentedI changed it to deal with variables with associative arrays in them, but don't see the syntax for non-associative arrays.
The IMCE_profile variable is an example:
with recursion, a part of the variable becomes:
where the 0, 1, 2 represent array indexes for non-associative arrays.
How should such a variable be represented in the xml? I'm afraid this feature is useless if it breaks some variables.
Comment #12
dan.nsk commentedHi, John
It seems to me that it is impossible to represent multi level arrays with numeric keys in xml (at least when we are talking about the Patterns module).
I have found a workaround to have a numeric key for a scalar (non-array) value:
this results in
But this method doesn’t work when a numeric key corresponds to an array value:
It would be nice for this structure to result in
but it does not.
It looks like that the only consistent way to represent an array with numeric keys is using YAML pattern syntax instead of XML.
Comment #13
R-H commentedHey,
Just wanted to say thanks for the generate patch for this module! I got it installed pretty easily and love the extra functionality.
Is this the latest patch?
http://drupal.org/files/issues/generate_1.patch
What's the status of incorporating this into the module?
Comment #14
vaish commentedJohnbarclay, thanks for working on this patch. This is something we wanted to do long time ago but never got to it.
It seems that patch in #9 is not the latest one. Could you please provide your latest patch that handles associative arrays? I would like to test it and work on adding support for handling numerical arrays as well. Also, please check out #613270: Syntax for XML patterns which enables defining numeric array keys in XML where support for arrays with numerical keys has been added to patterns.
Comment #15
chriscalip commentedsubscribe -note to self: dealing with settings on dev->staging->production
Comment #16
johnbarclay commentedI have to say that until there is the ability to deal with multilevel arrays, the patch is problematic. Someone could export and import such a variable and create some quite confusing problems.
Either it needs to be able to import and export such variables or that functionality should be taken out. That's why I'm changing the status back to needs work.
Comment #17
vaish commented@johnbarclay - did you notice comment #14? We do have some ways of handling multilevel arrays so it would be nice to incorporate that in your patch and commit it. Would you be interested working on this further? If not, just post your latest patch and I'll work on it.
Thanks
Comment #18
johnbarclay commentedI doesn't support multilevel arrays in variables yet. Are you saying that you have an approach to processing their representation...or to generating their representation (or both)?
I'm attaching the current code. Its just a file and the following menu items. I can't do a patch well because I have some other changes like ldap_integration that are hard to pull out.
I can integrate the multilevel arrays if you have the code snippets that deal with them, otherwise if its easier for you to do it yourself that is fine.
Comment #19
johnbarclay commentedI reworked this quite a bit; mostly to clean up the code. Attached is the patch.
To add support for multidimensional arrays, the "patterns_generate_array_to_xml" function in patterns.generate.inc will need the work.
If this approach works, I suppose some easy ones are taxonomy and menu for pattern generation.
Comment #20
vaish commentedThanks for the latest patch. I'm going to be away for the rest of the week and I will be able to check it out only when I come back. In the meantime here is a few ideas regarding multidimensional arrays.
Recently I added support for numeric array keys by introducing the following workaround:
When _numeric_keys="1" is specified, keys will be processed additionally and first character of the keys stripped out. This enables us to have valid XML while still producing numeric array keys after the XML is converted to PHP array. So, all you need to do is to prefix your numeric keys with a single character and make sure parent element has '_numeric_keys' attribute defined. I don't think this is very pretty but it works until somebody comes up with some better solution.
Much cleaner solution would be to use YAML instead of XML as a format for generated patterns. YAML doesn't need any workarounds and additionally you can make your code simpler by relying on spyc library for converting PHP array into YAML.
Main disadvantage is that spyc library doesn't come bundled with the patterns module so you can't be sure if it will be available always.
Patterns now also support PHP as a patterns format so that should also be considered as an option.
Cheers,
Vaish
Comment #21
johnbarclay commentedSounds good. I think before this gets committed, both yaml and xml should be supported. As well as the fix for multilevel arrays. I'll update this as I make progress.
Comment #22
vaish commented@johnbarclay: It's ultimately your choice what to work on first, but if I would have to chose between this patch and improvements to patterns form helper, I would give higher priority to patterns form helper.
Thanks
Comment #23
ChrisBryant commented@johnbarclay, have you made any progress on this work/patch since it was posted?
Comment #24
johnbarclay commentedNo progress. I'm behind on rewriting the ldap module so likely won't get a chance. If anyone wants to take this up, I think a function in patterns called patterns_array_to($array, $mode = "yaml"), where $mode = yaml, xml, etc would solve the problem of the multidimensional array.
Comment #25
anciano commented?