Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
field groups and various other required fields to be done first, perms require roles, etc.
One way is to add a weight to hook_features_api, however that seems... too dumb.
I'm thinking better is in in hook_features_api, something like 'rebuild dependencies' = array('fields'), and then we re-order, moving any component with that dependency to after their dependency.
Comment | File | Size | Author |
---|---|---|---|
#12 | 1997412-features-component-order-2.patch | 1.83 KB | dpfitzsi |
#8 | 1997412-features-component-order-1.patch | 2.1 KB | dpfitzsi |
#2 | 1997412-features-component-order.patch | 1.57 KB | mrfelton |
Comments
Comment #1
mrfelton CreditAttribution: mrfelton commentedSounds like a possible solution to #1063204-86: Adding a new permission causes integrity constraint violation. I like the component dependency idea.
Comment #2
mrfelton CreditAttribution: mrfelton commentedThis is basically the patch from #1063204-79: Adding a new permission causes integrity constraint violation with a minor issue fixed. Whilst it doesn't actually provide a way to order the components, it does adjust the component order to make user_permission last which fixes quite a few issues related to incorrect component ordering.
Comment #3
mglamanThis can be an issue when using UUID Features. For example if you're using UUID Features and exporting an entity bundle, that bundle may get created before the fields are attached. (This is happening on our situation.)
It would be a hacky work around, but what if alphabetical sort was used so all uuid_* components technically run last and we have some predictability on how components are built?
Or use drupal_sort_weight() sorting on components, new comment to follow.
Comment #4
mglamanCould use weight attribute using drupal_sort_weight().
When declaring hook_features_api():
This way components can be given a custom weight. Should probably introduce a features_api_alter() so users can alter the weights as needed.
This could load the components array and sort properly then.
Comment #5
AlfTheCat CreditAttribution: AlfTheCat commentedI tried the patch from #2 but in my case it failed. Perhaps its outdated?
Comment #6
mglamanAlfTheCat, the patch is highly outdated. There's been Features 2.1 and 2.2 since this was last discussed, in which component locking was introduced (I believe.) So a lot of things shifted around. Shouldn't be hard to re-roll.
Comment #7
GuyPaddock CreditAttribution: GuyPaddock commentedPlease consider whether the approach in #1216224: Provide documentation about feature component processing order that's already supported by Features would fit your needs.
Comment #8
dpfitzsi CreditAttribution: dpfitzsi commentedI have created a new patch against 7.x-2.5. It's the same patch provided by mrfelton, it just adds the changes into the correct lines.
Comment #9
dpfitzsi CreditAttribution: dpfitzsi commentedComment #12
dpfitzsi CreditAttribution: dpfitzsi commentedRolling a new patch against today's 7.x-2.x-dev
Comment #13
dpfitzsi CreditAttribution: dpfitzsi commentedComment #14
mpotter CreditAttribution: mpotter commentedI'm a bit confused on this one. I like the discussion about how to solve this generally, but the patch seems to only "fix it" for permissions. Can we get something that is a bit more general purpose than this? I hate to have hard-coded exceptions like this.
Comment #15
dpfitzsi CreditAttribution: dpfitzsi commentedHi mpotter,
I think in this case the only part that needs to be fixed are permissions. Permissions should be the last thing to be reverted in a feature. As comment #3 states, there can be a number of scenarios where permissions attempt to revert before entities are created.
Adding a general weight option though would be fine too. I guess putting in something on the features settings page with either checkboxes or a draggable weight list?
Comment #16
claudiu.cristeaI'm closing this in favor of #1814122: Allow components to be ordered by weight because there we already have a patch.