I'm currently trying to knit together the deployment features I want from a combination of install profiles, macro,
Install Profile API, CRUD, and a hobnailed collection of my own pseudo-CRUD macro helpers.
I like the re-use and share vision I see in patterns, but I need logic in my macros, so YAML and XML won't do that for me. If I can't dynamically retrieve system variables and do a few limited lookups like variable_get('image_gallery_nav_vocabulary', ''); then my 'patterns' will not be portable enough for what I need to do.
So I'm keep to keep using the PHP syntax. Down that path I see convergence with macro.module. (my home-brew solution includes form submission arrays as part of an install profile, and a macro-runner that does drupal_execute() on them. )
But I can't see the examples of PHP patterns that I can build and tune.
Looking at the code, I'm sure they are basic, but...
I see patterns_load_yaml() and patterns_load_xml(), So I guess I can emulate that, but will it work? No patterns_load_php() ?
Is there somewhere I should be looking?
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | patterns-php_support_and_bits.20070724.patch | 8.57 KB | dman |
| #2 | 011-editor_role_setup.pattern.php.txt | 1.72 KB | dman |
| #1 | patterns-support_php.patch | 1.78 KB | dman |
| #1 | 005-contact_page_setup.pattern.php_.txt | 673 bytes | dman |
Comments
Comment #1
dman commentedI'm guessing it should go something like this:
.. and a bit of psychic coding gave me:
Am I right?
Comment #2
dman commentedSorry for putting three things in one patch, but I didn't get any response to the first one, so needed to keep things moving forward.
OK.
This involved touching a few places to ensure that *.php files could be used the same as *.xml files. Does not yet save in php, but does read it.
(This involved a tiny refactoring of patterns_get_patterns() to abstract the search algorithm into a smaller function)
db_query('SHOW TABLES LIKE "cache_%"');and it threw errors when I tried on a prefixed site that had a different set of tables than the 'default' site.A small fix for this is attached.
when 'rid' was not an array. The code indicates that 'rid' is never expected to be an array, so I cast it into one to suppress the error. You'd only see it if running PHP_STRICT warnings - which I do.
Comment #3
sarvab commentedHi dman, sorry for not getting around to look at these much earlier. The patch looks great and my initial tests were fine so I just committed it. Will leave it open for review for a bit longer.
Thanks!
Comment #4
dman commentedCool, thanks.
I'm doing a bit of intensive cookie-cutter-site install-profile wizarding this week, so more tweaks may be forthcoming. I may even experiment with 'publishing' patterns...
The next one I need to do is one that auto-configures FCK Editor the way I want it ...
... after the one that creates a handful of boilerplate pages and content types...
Good fun, but slow going for me.
Comment #5
sarvab commentedSounds fun! Just why we have all these various solutions for doing just that. Hope things work out for you :)
Comment #6
ChrisBryant commentedNice work dman! It would be nice to also expose a permission for "Use PHP patterns" or something to that effect. I guess it's generally not that important since most of the time Patterns are run as user 1 or a fully privileged user anyways.
Also, it would be interesting to support PHP snippets that could be evaluated in XML or YAMP patterns. I'm not sure if that's a good idea technically but if possible and security considerations taken into place, it would be useful.
Comment #7
dman commentedWell, there certainly is a potential security issue with PHP evaluation anywhere.
I once cracked a system that had inadvertently left cck import open :-)
OTOH, I am really not in favor of Yet Another configuration language, when clearly a PHP array is as obvious, flexible, dynamic, portable and powerful enough for any set of configs I need.
So yeah, the thing to do is tie the ability to use eval() to the php filter permission, or something like that.
I guess you can embed ?php? tags directly into XML ... and have the processor eval them on the fly? ... Nah, I want to be able to use the full power, maybe a foreach. "A pattern that creates a node for each registered user". I'm treating patterns as bundled PHP 'snippets' that perform admin actions I guess...
Comment #8
sarvab commentedOne important aspect of using ?php? tags directly in XML/YAML ect is that you can have context available to you at that time. For instance if you're creating nodes, you won't know the node ids of what you're trying to create if you have a straight php pattern. If there was a
tag, you could put that in the right points in the pattern where you'll have context and access to all info from all actions completed up until that point.
One thing on the list of todos. Should really be an easy one too :)
Comment #9
brianjhoffman commentedI have encountered a problem with part 3 of the above patch when using patterns on a multi-site installation.
On our site, $db_prefix is an array, and so I need to hack line 1720 of patterns.module:
WAS:
$table = substr(current($table), strlen($db_prefix));
NOW:
$table = substr(current($table), strlen($db_prefix['default']));
I'm sure there would be a nice way to do this to support various configurations.
Here is our db_prefix array in the site settings file for reference:
$db_prefix = array(
'default' => 'mc_',
'users' => 'shared_',
'sessions' => 'shared_',
'role' => 'shared_',
'authmap' => 'shared_',
'sequences' => 'shared_',
'profile_fields' => 'shared_',
'profile_values' => 'shared_',
'blocks' => 'shared_',
'filters' => 'shared_',
'users_roles' => 'shared_',
);
Comment #10
dman commentedAh.
I've not worked with shared tables and prefix arrays yet. Must remember to consider those.
I don't know if there is a quick fix, could be tricky.
Comment #11
brianjhoffman commentedWell, thanks for reviewing. I'm glad it's on your radar at least. Let me know if you want any assistance when the time comes to revisit it.
Brian
Comment #12
vaish commentedRe #9: I improved code for clearing the cache by using a code snippet from Drupal core. I didn't test it with shared tables but I'm quite sure it should work now as it doesn't depend on db prefix at all.
Besides that, this patch has been committed long time ago so I'm closing this issue now.