You are here

function synonyms_commerce_product_options_expand in Synonyms 7

Expand the options for commerce product select widget with synonyms.

Parameters

array $options: Array of commerce product reference widget options that should be expanded with synonyms

Return value

array Expanded with synonyms version of the provided $options

1 call to synonyms_commerce_product_options_expand()
synonyms_commerce_field_widget_form in synonyms_commerce/synonyms_commerce.module
Implements hook_field_widget_form().

File

synonyms_commerce/synonyms_commerce.module, line 174
Provides synonyms integration with Commerce.

Code

function synonyms_commerce_product_options_expand($options) {
  $synonyms_options = array();
  $behavior_implementations = array();
  foreach (commerce_product_load_multiple(array_keys($options)) as $product) {
    if (!isset($behavior_implementations[$product->type])) {
      $behavior_implementations[$product->type] = synonyms_behavior_get('select', 'commerce_product', $product->type, TRUE);
    }
    $synonyms_options[] = synonyms_select_option_entity($product, 'commerce_product');
    foreach ($behavior_implementations[$product->type] as $behavior_implementation) {
      foreach ($behavior_implementation['object']
        ->extractSynonyms($product) as $synonym) {
        $synonyms_options[] = synonyms_select_option_entity($product, $behavior_implementation['entity_type'], $synonym, $behavior_implementation);
      }
    }
  }
  usort($synonyms_options, 'synonyms_select_sort_name');
  return $synonyms_options;
}