Allows entity reference fields to be used to create combinations on the bulk product creation form provided in Commerce BPC.
This functionality is useful if you want to use entity reference fields as user-selectable attributes for products. For example, one combination set could include list field values "red" and "blue," and entity reference values "node 1" and "node 2."
Project page: http://drupal.org/sandbox/dpolant/1331986
Git: git clone --branch master dpolant@git.drupal.org:sandbox/dpolant/1331986.git commerce_bulk_product_create_entity_reference
BPC entity reference is Drupal 7 only.
Comments
Comment #1
sven.lauer commentedAs the commerce_bpc maintainer, I thought should do a (partial) review of this.
This is a useful module---entity reference fields can be a clever way to do configurable "product bundles". Another use case would be to "sell" any kind of entity (think nodes with "premium content", etc.).
Here are a couple of things I noticed:
- I recommend to name the product after the module "bpc_entityreference" instead of "commerce_bulk_product_create_entity_reference".
- You are using the "master" branch. From looking at other reviews in the queue, it seems that it is recommended to use a 7.x-1.x branch already in the sandbox---you'll need to do this for dev releases anyways, so you might switch right now, as well.
- The module does pretty well wrt to coding standards, but there are some minor issues that the coder review module can help you detect:
-- Three functions don't have a space between the closing ) of the argument list and the opening {
-- A couple of lines have extra white space.
-- One of the doc headers misses the parens after "Implements hook_foo"
(Make sure to set coder to "minor" to see all of those reported.)
- As per the recommendation in the bpc API doc, you keep track of the "combination" fields managed by your module in $form_state, and you do check whether there is a value in
$form_state['commerce_bpc']['bpc_entityreference']['combination_fields']---but then you iterate over all fields in$form_state['values']['combination']anyways. Since there is a check withentityreference_field_is_empty($columns, $field_name), this UNLIKELY to create problems, unless (i) some module has the same columns as entityreference and (ii) this module has its own combination-creating module. Granted, this is unlikely at present, but it is something that you should guard against. Basically, I recommend that instead of doing:simply do something like
That way, you'll only loop over the fields that are managed by your module (saves a couple of iterations, too!).
- Your module has a nice feature that the current bpc "core" implementations do not have: Offer a "none" option, that, if selected, creates a variant that does not have a value for the field (along with those that do). That is a very nice idea, and one that commerce_bpc will adopt---thanks for the inspiration! Yet, there are two issues I have with the current implementation:
(i) The "none" option is appended to the end of #options---I think it would be better if it showed at the beginning---perhaps to an array_unshift, instead of just appending the value?
(ii) I think the "None" option should be there only of the field is not required---for if it is, no products without a value for the field should be created. Currently, the "None"-option is there regardless of the "required" setting.
(A note to fellow reviewers: The module includes a comment
// force static is not actually implemented yet. This is appropriate, as any such implementation would be futile, given the core bug #765860: drupal_alter() fails to order modules correctly in some cases---basically, bpc_entityreference would be trying to add a setting to a fieldset that is only created later. This could be fixed by implementing hook_module_implements_alter(), if it were not for the core bug referenced.Comment #2
dpolant commentedI have completed all of these items:
- module renamed
- made 7.x-1.0-dev branch
- fixed standards typos (haven't looked for whitespace yet though)
- changed get combinations section to actually respect logged fields
- moved "none" to top of list
- omitted "none" if field required
Comment #3
sven.lauer commentedA few notes:
(i) The correct name for the -dev branch would be "7.x-1.x" (see http://drupal.org/node/1015226 )
You can rename branches using
git branch -m oldname newname, but I don't know how well this works with remote branches.(ii) You are checking for
!$instance['settings']['required']), but the "required" setting is not actually stored in the 'settings' sub-array,so this should really be !$instance['required'], or better yet !empty($instance['required'] to guard against a missing setting.
(iii) I am not sure what you intended to do with the options and "None", but the additional option still shows up at the end. Also, you added the line
but $options is defined nowhere---presumably, you wanted to operate on $element[$lang]['#options'], instead.
(iv) With respect to white space, I recommend figuring out a way to configure your editor to strip out trailing whitespace on saving. Do it once and you'll never have to worry about this again ;)
Almost all editors can do this, there are some hints about configuring your editor for drupal development in the subpages (at the bottom) of this page:
http://drupal.org/node/147789
Comment #4
sven.lauer commentedAlso, you renamed the project to "bpc_entity_reference", while your module is called "bpc_entityreference".
Technically "bpc_entity_reference" is adhering to the standards better, but at the same time, given that the module you are integrating is (non-standardly) called "entityreference", a case could be made that you should use the same name. Your call. If you decide to change the name of the module to bpc_entity_reference, you'd have to rename the hook implementations, of course.
Comment #5
dpolant commentedYeah ... I think I accidentally deleted a line that set up a reference between $options and $element[$lang]['#options']. I fixed that and refactored a bit to eliminate some of the repetition.
Also I was testing today and I found and fixed a bug that was preventing "not-none" combinations from being created when the "none" option was selected for the entity reference field.
I ran the coder module and fixed the remaining standards issues. Also I removed trailing whitespace from the files.
Dev branch is now: 7.x-1.x
Git: git clone --branch 7.x-1.x dpolant@git.drupal.org:sandbox/dpolant/1331986.git
As far as the naming goes, I'm not sure how to accomplish what I want. I want the label of the project to be "BPC Entity Reference" while having the folder and project name be "bpc_entityreference." The directory name that shows up in the auto-generated git clone command seems to be dependent on the project name I set in the edit tab of the project, but I want these to be different.
Comment #6
doitDave commentedAutomated review (Please keep in mind that this is primarily a high level check that does not replace but, after all, eases the review process. There is no guarantee that no other issues could show up in a more in-depth manual follow-up review.)
Review of the 7.x-1.x branch:
This automated report was generated with PAReview.sh, your friendly project application review script. Go and review some other project applications, so we can get back to yours sooner.
Manual review:
Comment #7
dpolant commented- Master branch truncated
- Module now passes coder with no problems
- I addressed the issues found by PAReview.sh
Comment #8
sven.lauer commentedOkay, all the standards issues are fixed.
Functionality / code wise, I think this is ALMOST good to go, except:
You are using that
attribute_fieldsetting introduced/managed by the commerce_cart module (basically as a workaround for the non-working 'treat as static' setting) ... so you should depend on commerce_cart.I am aware that this is a "do as I say, not as I do" moment (as the bpc_taxonomy module included with commerce_bpc does NOT currently depend on commerce_cart, though it should---and will, in the next (rc)-release), but still.
Once you add a
dependencies[] = commerce_cartto the .info file, I think this is good to go.Comment #9
dpolant commentedCart is now a dependency.
Comment #10
sven.lauer commentedThis is green, then.
Comment #11
rfayGit vetted user role granted. Welcome, and thanks for your current and future contributions!
Thanks to all for the careful reviews! Thanks @sven.lauer, @doitDave
Don't forget to review other applications, as this queue can get burdensome without lots of people helping out.
Comment #13
avpaderno