Patch for Generating Variable, Role, and Perm Patterns from existing site.

johnbarclay - July 9, 2009 - 02:35
Project:Patterns
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:reviewed & tested by the community
Description

This patch adds an interface for generating variable, roles, and perms for a site based on existing configuration. The idea is to speed up the pattern generation process. It makes no attempt at generating a "complete" pattern that solves a particular configuration use case.

Its use case is generate some xml elements that can be pasted into a pattern.

A 4 minute walk through is at:

http://www.youtube.com/watch?v=NmwZmKS7S30

AttachmentSize
patterns_generate.patch17.26 KB

#1

ChrisBryant - July 11, 2009 - 07:58

This 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!

#2

johnbarclay - July 11, 2009 - 15:34

Sounds 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.

#3

paulap - July 26, 2009 - 14:39
Title:Patch for Generating Variable, Role, and Perm Patterns from existing site.» Doesn't work for me - No Generate tab

Hi,

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

#4

sarvab - July 26, 2009 - 21:28

If 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 ;)

#5

paulap - July 26, 2009 - 21:54
Title:Doesn't work for me - No Generate tab» Thx - SOLVED

#6

sarvab - July 28, 2009 - 09:01
Status:needs review» closed

#7

sarvab - July 28, 2009 - 09:02
Status:closed» needs review

#8

sarvab - July 28, 2009 - 09:02
Title:Thx - SOLVED» Patch for Generating Variable, Role, and Perm Patterns from existing site.

#9

johnbarclay - October 23, 2009 - 18:47
Status:needs review» reviewed & tested by the community

This 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.

AttachmentSize
generate.patch 17.21 KB

#10

joestewart@drup... - October 26, 2009 - 12:07

The 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.

#11

johnbarclay - October 27, 2009 - 07:16

I 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:

a:2:{i:1;a:9:{s:4:"name";s:6:"User-1";s:8:"filesize";i:0;s:5:"quota";i:0;s:7:"tuquota";i:0;s:10:"extensions";s:1:"*";s:10:"dimensions";s:9:"1200x1200";s:7:"filenum";i:0;s:11:"directories";a:1:{i:0;a:7:{s:4:"name";s:1:".";s:6:"subnav";i:1;s:6:"browse";i:1;s:6:"upload";i:1;s:5:"thumb";i:1;s:6:"delete";i:1;s:6:"resize";i:1;}}s:10:"thumbnails";a:3:{i:0;a:4:{s:4:"name";s:5:"Small";s:10:"dimensions";s:5:"90x90";s:6:"prefix";s:6:"small_";s:6:"suffix";s:0:"";}i:1;a:4:{s:4:"name";s:6:"Medium";s:10:"dimensions";s:7:"120x120";s:6:"prefix";s:7:"medium_";s:6:"suffix";s:0:"";}i:2;a:4:{s:4:"name";s:5:"Large";s:10:"dimensions";s:7:"180x180";s:6:"prefix";s:6:"large_";s:6:"suffix";s:0:"";}}}i:2;a:9:{s:4:"name";s:14:"Sample profile";s:8:"filesize";i:1;s:5:"quota";i:2;s:7:"tuquota";i:0;s:10:"extensions";s:16:"gif png jpg jpeg";s:10:"dimensions";s:7:"800x600";s:7:"filenum";i:1;s:11:"directories";a:1:{i:0;a:7:{s:4:"name";s:5:"u%uid";s:6:"subnav";i:0;s:6:"browse";i:1;s:6:"upload";i:1;s:5:"thumb";i:1;s:6:"delete";i:0;s:6:"resize";i:0;}}s:10:"thumbnails";a:1:{i:0;a:4:{s:4:"name";s:5:"Thumb";s:10:"dimensions";s:5:"90x90";s:6:"prefix";s:6:"thumb_";s:6:"suffix";s:0:"";}}}}

with recursion, a part of the variable becomes:

...
<thumbnails>
  <0>
  <name>Small</name> 
  <dimensions>90x90</dimensions> 
  <prefix>small_</prefix> 
  <suffix></suffix> 
  </0> 
  <1>
  <name>Medium</name> 
  <dimensions>120x120</dimensions> 
  <prefix>medium_</prefix> 
  <suffix></suffix>  </1> 
  <2>
  <name>Large</name> 
  <dimensions>180x180</dimensions> 
  <prefix>large_</prefix> 
  <suffix></suffix> 
</2> 
</thumbnails>
...

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.

#12

dan.nsk - October 27, 2009 - 18:30

Hi, 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:

<var>
   <value tag='10'>aaaa</value>
   <value tag='11'>bbbb</value>
   <value tag='12'>cccc</value>
</var1>

this results in
$var[10] = 'aaaa';
$var[11] = 'bbbb';
$var[12] = 'cccc';

But this method doesn’t work when a numeric key corresponds to an array value:

<var>
   <value tag=’11’>
      <next_level_key_1>aaaa</next_level_key_1>
      <next_level_key_2>bbbb</next_level_key_2>
   </value>
   <value tag=’12’>
      <next_level_key_1>cccc</next_level_key_1>
      <next_level_key_2>dddd</next_level_key_2>
   </value>
</var1>

It would be nice for this structure to result in

$var[11]['next_level_key_1'] = 'aaaa';
$var[11]['next_level_key_2'] = 'bbbb';
$var[12]['next_level_key_1'] = 'cccc';
$var[12]['next_level_key_2'] = 'dddd';

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.

 
 

Drupal is a registered trademark of Dries Buytaert.