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.
foreach (field_info_instances('commerce_product', $type) as $name => $instance) {
// A field qualifies if it is single value, required and uses a widget
// with a definite set of options. For the sake of simplicity, this is
// currently restricted to fields defined by the options module.
$field = field_info_field($instance['field_name']);
$instance['field_name'] is also just the $name.
Though that would probably be better called $field_name.
Comment | File | Size | Author |
---|---|---|---|
#3 | 1784508-3.field_name.patch | 1.65 KB | rszrama |
Comments
Comment #1
thomaske CreditAttribution: thomaske commentedI cloned the 7.x.1 structure and searched the files for the offending code.
I found what appears to be the code in a module called commerce_product_controller.inc.
But the reference does not have the comments found in the quoted section. And it appears that if you change the name of the variable, it will overwrite a variable with the same name listed a few lines earlier.
Has it been changed significantly in the .dev version? Please advise.
tk
Comment #2
joachim CreditAttribution: joachim commentedI can see it in the latest dev.
Search for the string 'A field qualifies if it is single value'
Comment #3
rszrama CreditAttribution: rszrama commentedI'm hesitant to change this. It's a bit of "if it ain't broke, don't fix it." As far as I was concerned, "$name" was the instance name - but it was mostly just a throwaway key value (you can see it isn't used anywhere inside that loop). However, looking at _field_collate_fields(), it is in fact keying the array per bundle by the instance field name. We'll make sure it passes test bot, and I suppose there's no reason not to change it.
A file name next time would help. ; )
Comment #4
joachim CreditAttribution: joachim commentedSorry! I think this was one of those things I meant to make a patch for and then forgot!
Comment #5
rszrama CreditAttribution: rszrama commentedCleaning up my backlog; just committed this.