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.
1) export object something that doesn't have ->export method
2) notice it exports as purely an array and not an object at all.
3) go wat? at the exported array instead of object
Attached patch takes care of #1437262: \Drupal\Component\Utility\Variable::export on object of custom class but no __set_state method creates unusuable export (fatals)
I'm not sure why it's doing this or if changing it will effect any existing exports (which should be switching them to arrays first if they want their export to be an array, IMO).
Comment | File | Size | Author |
---|---|---|---|
#13 | features-var-export-object-1437264-12.patch | 1.06 KB | ricovandevin |
| |||
#11 | features-var-export-object-1437264-11.patch | 1.06 KB | bforchhammer |
|
Comments
Comment #1
seanrThis patch isn't working for me when I try to export uc_quote_store_default_address via strongarm.
Comment #2
hefox CreditAttribution: hefox commentedCould you expand on what you mean by "isn't working"?
Comment #3
David_Rothstein CreditAttribution: David_Rothstein commentedHere's a reroll to apply to the latest 7.x-1.x codebase (also borrowing some of the code comment from #1437262: \Drupal\Component\Utility\Variable::export on object of custom class but no __set_state method creates unusuable export (fatals) ).
Comment #4
mpotter CreditAttribution: mpotter commentedThe only problem I have with this is it ends up causing a lot of existing features to get marked as "overridden". Looks like exports are just in a different order in most cases. But I'd like to have more eyes review this before committing it.
Comment #5
hefox CreditAttribution: hefox commentedI think this has a chance of having significant enough impact on anyone that it's best to wait till after features stable is released (do we have a tag/way to indicate that?).
Since the exports using this were rendered to arrays instead of objects, the hook_features_rebuild will need to be updated to use objects (or arrays?) have to convert their objects to array's before running features_var_export. I believe I saw this with features UUID.
Comment #6
bforchhammer CreditAttribution: bforchhammer commentedIn #1865058: Variable appears to be saving objects from {variable} as arrays, which breaks language_default we also stumbled on this problem with the
language_default
variable (which a stdclass object).Without the patch it's just exported as an array, which causes problems when the feature is rebuilt. With the patch in #3, the variable code is exported as
(object) array(...)
and rebuilding works again.Tentatively marking as RTBC... It would be great to see this make it's way into the code base!
Comment #7
mpotter CreditAttribution: mpotter commentedI don't see any new patch addressing the issues from #4 and #5 so this is certainly not RTBC until those get handled.
Comment #8
Martijn Houtman CreditAttribution: Martijn Houtman commentedI ran into the same problem with language_default not being imported properly (as an array, rather than an object).
The patch in #3 works fine for me, and actually solves the issue that my 'realm variables' show as overwritten. So #4 is actually reversed, in my case.
Comment #9
xmacinfoI am having this issue with variables 7.x-2.4.
Using "Variable translation" to have a multilingual slogan, and using Features to export the slogan, the language_default is saved as an array, instead of an object.
I need to do the following in a hook_update:
Where is the code responsible for generating the feature file ending with “.variable.inc”?
Comment #10
bforchhammer CreditAttribution: bforchhammer commentedI just stumbled on this problem again as well.
Bumping version as it should be fixed in 2.x first (right?); probably needs a re-roll.
Comment #11
bforchhammer CreditAttribution: bforchhammer commentedHere's a reroll against the 2.x branch.
The issue mentioned in #4 with a lot of existing features getting marked overriden still persists, as it affects at least taxonomy vocabularies, filters, languages, role definitions, menus, and also variables of a couple of contrib modules (metatag, wysiwyg and tmgmt in my case).
As far as the
language_default
variable goes, I would probably want the feature to get marked overwritten (to indicate that it needs to be updated), but I'm not sure about the other cases. Therefore leaving as "needs work".Comment #12
ricovandevin CreditAttribution: ricovandevin commentedThe patch in #11 was not working for us in version 7.x-2.2. Attached a patch for that version.
Comment #13
ricovandevin CreditAttribution: ricovandevin commentedHmmm... I didn't sanitize the diff file generated by Git. Attached a clean version of the patch for 7.x-2.2.
Comment #14
ricovandevin CreditAttribution: ricovandevin commentedWe have used the patch from #11 (with a slight change, see #12/#13) to solve the issue for language_default. Now we are further in our project and we ran into issues like the one mentioned in #5. Both Wysiwyg and Metatag expect information that is normally in an object to be in the features as an array. With the patch this information is stored in the features as objects, causing errors on feature revert.
We'll have to look into this issue much deeper to find a generic solution.
EDIT
For now we have solved this by unpatching Features and implementing
hook_post_features_revert()
in the .module file of the feature that contains the language_default variable. Example:Comment #15
shi99 CreditAttribution: shi99 commentedThanks for your temp solution ricovandevin in #14.
It helped a lot in solving my issue.
Comment #16
alexharries CreditAttribution: alexharries commented+1 to ricovandevin's fix in #14 - this also fixed it for me, so thank you :)
Comment #17
Kristen PolComment #18
kenorb CreditAttribution: kenorb commentedComment #19
mpotter CreditAttribution: mpotter at Phase2 commentedI'm not seeing any new patch to review here that addresses #14. Also would need to know if this problem still occurs in 7.x-2.10 since there were changes in the past couple updates to this recursive export procedure.
Comment #20
joelpittet@mpotter i can confirm it still occurs. Went with a fix in the other module though that changed them to arrays. Had to re save each view, for that to work but it did.
This would be nice to let contrib save the results as object too
Comment #21
mpotter CreditAttribution: mpotter at Phase2 commentedOK, and it seems the issues in #4 and #5 are still not addressed, so leaving this as "needs work". Honestly don't see a lot of hope getting something this major changed at this late point of development, especially since this kind of thing isn't needed in D8 where we have proper yml files for export.