Needs work
Project:
UUID Features Integration
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
17 Dec 2013 at 07:41 UTC
Updated:
27 Nov 2019 at 18:00 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
rogical commentedComment #2
rogical commentedonce #2158049: Allow alter field variable during field export is fixed and committed, I'll update a patch for this.
Comment #3
rogical commentedUpload a patch for features 1.x version
Comment #4
rogical commentedComment #5
kristiaanvandeneyndeChanging to bug report because I found out that there was already code for this inside uuid_features, but it was still targeting Drupal 6 inside the Drupal 7 version. ($node->taxonomy)
So what I did is:
What the code does:
Note that this still needs the latest patch from the related issue to work.
#2158049-7: Allow alter field variable during field export
Comment #6
kristiaanvandeneyndeComment #7
kristiaanvandeneyndeRemoved some more legacy code: uuid_term.features.inc was still checking for term reference fields, but those are handled by this patch now. (Field instances are exported along with the vocabulary dependency and thus trigger the taxonomy term reference code).
Comment #8
kristiaanvandeneyndeSorry for the noise, but I keep finding 'leftover' code from D6.
Comment #9
ladybug_3777 commentedI've applied the patch on this page from comment #8 and the patch from comment #7 on the referenced issue for features. (https://www.drupal.org/node/2158049#comment-8419075).
Unfortunately after applying them both I get the following error if I attempt to recreate an existing feature:
PHP Fatal error: Call to undefined function uuid_term_features_get_dependencies() in "MyDrupalRoot"\sites\default\modules\uuid_features\uuid_features.module on line 102
Am I missing a step here?
Comment #10
ladybug_3777 commentedOr is there a different/better way for me to export the default value on a content type that is linked to a taxonomy term id? My main motivation is so that I can easily transfer this feature from one server to another where internal taxonomy_ids are different.
Comment #11
nimoatwoodwaySame problem here: PHP Fatal error: Call to undefined function uuid_term_features_get_dependencies() when applying patch from #8 to 7.x-1.0-alpha4. Is there a nice solution for that problem?
Comment #12
das-peter commentedI guess this patch needs a re-roll.
Comment #13
kristiaanvandeneyndeThe patch removed uuid_terms_features_get_dependencies() without issues earlier. This means the latest version of UUID Features added a call to said function somewhere.
Comment #14
@James commentedWe created a patch which can solve the uuid issue for taxonomy term reference field type.
Comment #16
@James commentedComment #17
@James commentedComment #18
das-peter commented@Mover thank you very much for the re-roll, I just gave it a quick visual review. Mostly there are just coding standard nitpicks.
However, from a quick review it seems the patch from #8 has a more comprehensive feature-set e.g. dependency management. So I'm not sure how we'll proceed here.
Looks like a hook implementation - thus it should also use the documentation style: Implements hook_...().
Could we mention what is done here.
E.g. "Ensure the configured default value of a term reference field is properly set."
Expected 1 space after if to match the coding standards.
Expected 1 space after foreach to match the coding standards.
The else should be on a new line to match the coding standards.
Last element in an multiline array declaration should be trailed by a comma to match the coding standards.
Could we mention here what's going on.
E.g. "Ensure the default values of taxonomy term reference fields are exported as uuids".
I think this condition can be simplyfied to:
if(!empty($instance['default_value'][0]['tid']))
Comment #19
@James commentedThank you Peter Philipp and your review!
I have corrected some lines to match the coding standard. Regarding to some of your questions, please see the below answers:
1. I placed the two hook implementations in the uuid_features.module, there are a few reasons:
2. Use isset to validate tid, just want to avoid the notice in PHP logs.
Thanks,
Comment #20
das-peter commented@Mover thanks for the updated patch. I think there were misunderstandings about some parts of my review:
In 1. I don't question why the hooks are in the module file - since hooks usually belong there. The only thing is that if you implement a hook the function documentation should follow the coding / doxygen standards https://www.drupal.org/node/1354#drupal which says:
Working like that allows others to quickly discover what hooks are used by a module by simply searching for "Implements hook_".
Regarding 8. there's simply no need to use both
isset()andempty(), empty works like isset, but also checks if there's an empty / no value. So by switching toif(!empty($instance['default_value'][0]['tid']))you'll check the most specific requirement right away, still without the danger of getting a notice.You can even run the command below, where
$instanceisn't available at all and won't get a notice:Try it with https://3v4l.org/kESBP
Hope this helps to clarify those points :)
Comment #21
@James commentedThank you Peter Philipp! I appreciate your comments very much! I have corrected them.
Comment #22
liam morlandRe-roll to apply to 7.x-1.x with spelling correction in comments and comments wrapped.
Comment #23
@James commentedComment #24
istryker commentedLooks like the patch export correctly.
Marking as 'needs work' as when you 'review overrides' it only shows the 'tid'. It should show 'tid' and 'uid'. This happen when you have a field as part of a feature (without a default value), then add a default value to it.
Comment #25
@James commentedI didn't get the issue, so I assume that is caused by the cache issue.
Comment #26
@James commentedComment #27
liam morlandRe-roll.
Comment #29
liam morlandTesting failed because there are no tests.
Comment #30
donquixote commentedI am not convinced of this patch.
Observation: Noise in the stored default value
When saving the field edit form at admin/structure/types/manage/***/fields:
In taxonomy_autocomplete_validate(), the default value is replaced with the complete term object, and this is saved in the instance settings in the database. This contains the uuid, but a lot of other unnecessary stuff as well.
Problems in this patch
With this patch, on features export, the module would call field_update_instance() to overwrite the field instance config, setting the new format for the default value.
Exporting a feature should have no side effect on the field instance stored in the database.
Another problem is there seems to be a real bug in uuid_features_features_export_alter():
If there are two values in the default value, one of them has a uuid and the other has not.
Then $default_values will contain only one of the two item.
So one item will be lost when saving.
In uuid_features_features_export_alter(), if one of the values does not contain a 'uuid', the stored default value will be replaced with ['uuid' => .., 'tid' => ...], removing all the noise. However if the default value already contains a 'uuid', then it remains as it is.
For features this means that sometimes the export will contain the entire term, sometimes it will only contain uuid and tid for the default value.
Conclusion:
This patch adds unpredictability and possible side effects, in the worst case it may cause data loss.
Comment #31
donquixote commentedWhat would be the correct way to do this?
The correct solution would be:
The rewritten default value should only be written to the feature, not to the database of course!
What would be a cheaper workaround?
If the "bug" from previous message was not there, perhaps we could risk to save the default value in uuid_features_features_export_alter().
I don't think this should be committed to the uuid_features module, but it would then be more viable as a patch that people can apply until a real solution is found.
Comment #32
donquixote commented#2158049: Allow alter field variable during field export did attempt to introduce such hooks in features. It has its own problems, though.
Adding this to every feature seems repetitive.
Comment #33
liam morlandRe-roll of #27.