From http://drupal.org/node/693024#comment-3462560 #693024: Add alter hooks for the "faux" exportables.
Had two issues in features_get_default.
Whether to alter or not doesn't work without resetting as it doesn't track that the items have been altered or not yet (bug)
hook_node_info_alter is called but can't do anything as features doesn't handle this implementation, so patch adds an alter_state for features_api to make sure running alter is okay.. and adds drupal_alter when exporting a filter so node info can be altered (which is extremly useful; dynamic naming of content types!)! (feature request).
Patches iterconnected as one as one effects the other.
Comment | File | Size | Author |
---|---|---|---|
#30 | 984472-features_hook_node_info_alter-30.patch | 682 bytes | hefox |
#25 | features-node_info_alter-984472-25-D6.patch | 3.36 KB | scottrigby |
#20 | features-node_info_alter-984472-20.patch | 3.25 KB | mpotter |
#19 | features-node_info_alter-984472-19.patch | 4.55 KB | Sarenc |
#18 | features_node_info_alter-984472-18.patch | 4.89 KB | hefox |
Comments
Comment #1
hefox CreditAttribution: hefox commentedComment #2
Grayside CreditAttribution: Grayside commentedI've tried various ways of applying one or two patches to test this, and I'm not getting all the needed changes applied. Either there is a broken patch, or I need simpler instructions :)
I didn't like the documentation for features_get_alter_state() so I took a stab at rewriting it. Would have made a patch, but
Comment #3
hefox CreditAttribution: hefox commentedI was probably manually editing the patch or had some other patches, or some sort if sillyness that prevented it applying. I'll remake the patch, hopefully tonight.
Comment #4
goron CreditAttribution: goron commentedHere's a rebuilt patch that applies cleanly to the 6.x-1.1 release and current dev (there were a few small changes to one of the functions).
Comment #5
hefox CreditAttribution: hefox commentedGoing to update this patch
Comment #6
hefox CreditAttribution: hefox commentedPatch depends on #1390848: Centralize the call to hook_features_api().
What it does is add two new potential, non-required keys to hook_features_api
This way a module can indicate if there is an alter hook, and what it is (and if an export needs to define it -- truefully don't alter_info it being used outside of hook_node_info, though there may be other core like that).
Adding some mess with an global to say whether to run an alter, not really happy about that.
Comment #7
hefox CreditAttribution: hefox commentedPatch does not deal with the features_get_default bug anymore, focusing on the feature request.
Comment #8
hefox CreditAttribution: hefox commentedNeed to update it for image styles
Comment #9
mpotter CreditAttribution: mpotter commentedI like most of the ideas in #6, but I'm wondering why the Node exportable needs the new inline alter added to it. Doesn't the existing features_get_default call drupal_alter for the default_hook already? Why does Node need to be different/special?
Comment #10
hefox CreditAttribution: hefox commentedfeatures_get_default is just a helper function for features to help it generically call default hooks by module and only used 'for real' for hooks that features itself has provided (fields, filters). hook_node_info (and image), while given features support via features itself, are core hook called by core functions ( _node_types_build, image_styles()), so cannot add any hook that is not already there in core. :-/
Comment #11
mpotter CreditAttribution: mpotter commentedConfused. Still seems like features_get_default is already calling drupal_alter('node_info', ... and thus the "inline" drupal_alter call is not needed, so I'm not sure you answered my question.
Comment #12
hefox CreditAttribution: hefox commentedhook_node_info is a hook used by core. Core does not use features_get_default to call it, core uses _node_types_build.
Comment #13
hefox CreditAttribution: hefox commentedComment #14
hefox CreditAttribution: hefox commentedI still reallly don't like the global/etc. doing in the patch, but it's sorta a screwy situation.
Comment #15
Grayside CreditAttribution: Grayside commentedYou could replace it with a wrapper function that hits a statically cached value. That would avoid bad global mojo and perhaps simplify debugging.
Comment #16
hefox CreditAttribution: hefox commentedFixing type in alter hook for image (image_style => image_styles).
Meh, wrapper function is unnecessary overhead
Comment #17
mpotter CreditAttribution: mpotter commented+++ b/includes/features.node.inc
@@ -86,6 +87,10 @@ function node_features_export_render($module, $data, $export = NULL) {
+ $output[] = ' global $features_alter;'; ¶
whitespace at end of line
Also failed to apply to latest 7.x-1.x-dev version.
Otherwise I think the approach is good.
Comment #18
hefox CreditAttribution: hefox commentedHere's an reroll against a fresh pull of 7.x-1.x so hopefully it applies (with the white space removed)
Comment #19
Sarenc CreditAttribution: Sarenc commentedThe last patches weren't applying against the 6.x-1.x-dev of Feb 22/2012 so I re-rolled one.
I didn't see an /includes/features.image.inc file so I ignored that bit.
Comment #20
mpotter CreditAttribution: mpotter commentedI'm still not happy with the way the alter hook for node is implemented. The use of the global features_alter variable just seems kludgy. For the sake of trying to get the really important piece of this patch into Features soon, here is a reduced patch for the 7.x-1.x-dev version that removes the global and the node alter and just contains the core code to add the new alter hook information to the api.
Comment #21
hefox CreditAttribution: hefox commentedsounds good to me
Comment #22
mpotter CreditAttribution: mpotter commentedCommitted f7447af
Comment #23
mpotter CreditAttribution: mpotter commentedAlso, the node stuff should go to a new issue if we can figure out a better way.
Comment #24
hefox CreditAttribution: hefox commentedComment #25
scottrigbyMerged f7447af to 6.x-1.x & patched for review.
Comment #26
hefox CreditAttribution: hefox commentedCan't do this till #1390848: Centralize the call to hook_features_api() is backported.
Comment #27
mxmilkiib CreditAttribution: mxmilkiib commentedI'm looking to export a forum setup to a feature.
I've patched Features 6.x-1.x-dev with #23 on #1390848: Centralize the call to hook_features_api() and #25 here, but I'm not getting 'Forum topic' in the Content types.
Is there a further step I should be taking? Or am I viewing this the wrong way, or simply barking up the wrong tree? Thanks for any advice.
Comment #28
DamienMcKennaBump for testbot.
Comment #29
hefox CreditAttribution: hefox commentedThis is not going backported I think, so kicking this back to 7.x to add the hook_node_info_alter that was part of the original patches
Comment #30
hefox CreditAttribution: hefox commentedComment #31
marcusx CreditAttribution: marcusx commentedThanks!
I had a content type named "Show" and needed to swap the
t()
function for adding some context so I can avoid the translation of the content type name. Works like expected. Here is my hook as an example for a potential use case.Comment #32
hefox CreditAttribution: hefox commented