This patch solves the problem in commerce_line_item_field_widget_form when line_items array is empty.

Comments

michee.lengronne’s picture

StatusFileSize
new799 bytes

Hum, I think this one is better.

rszrama’s picture

Priority: Major » Normal
Issue tags: +sprint

Tagging. Patch will need review for code formatting.

mglaman’s picture

Assigned: michee.lengronne » Unassigned
+++ b/modules/line_item/commerce_line_item.module
@@ -999,7 +999,12 @@ function commerce_line_item_field_widget_form(&$form, &$form_state, $field, $ins
+      $line_items = commerce_line_item_load_multiple($line_item_ids);

Shouldn't commerce_line_item_load_multiple() return an empty array from entity_load() anyways?

rszrama’s picture

It's actually a lovely "feature" that it will return literally every entity of the given type. Not sure what drove that decision. : P

mglaman’s picture

Status: Needs review » Reviewed & tested by the community

Marking this as RTBC, then. Looks good, will properly handle empty line items.

Only change is we could make it

$line_items = (!empty($line_item_ids)) ? commerce_line_item_load_multiple($line_item_ids) : array();

But that's super nitpick, and broken out it's easier to read logic going on here and assume why we're doing this check.

rszrama’s picture

Nit picking is good. : D

I think we generally prefer the if / else block over the ternary operator. We do need to fix the code style though to remove the extra line of whitespace and put the curly brace before the else on a line by itself.

michee.lengronne’s picture

The code style is normally fixed now. It seemed to be uploaded twice (weird).

mglaman’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.