You are here

function _webform_render_productfield in Commerce Webform 7.2

Same name and namespace in other branches
  1. 8 productfield.inc \_webform_render_productfield()
  2. 7 productfield.inc \_webform_render_productfield()

Implements _webform_render_component().

File

./productfield.inc, line 193

Code

function _webform_render_productfield($component, $value = NULL, $filter = TRUE) {
  $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
  $product_ids = _webform_productfield_product_ids($component);
  $element = array(
    '#type' => 'webform_productfield',
    '#choose_quantity' => !empty($component['extra']['choose_quantity']),
    '#multiple' => !empty($component['extra']['multiple']),
    '#productids' => $product_ids,
    '#required' => !empty($component['required']),
    '#default_value' => isset($value) ? $value : _webform_filter_values($component['value'], NULL, NULL, NULL, FALSE),
    '#weight' => $component['weight'],
    '#aslist' => !empty($component['extra']['aslist']),
    '#name' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
    '#title_display' => $component['extra']['title_display'],
    '#theme_wrappers' => array(
      'webform_element',
    ),
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'commerce_webform') . '/commerce_webform.js',
      ),
    ),
  );
  if (empty($component['extra']['choose_quantity'])) {

    // If we are not allowing the use to select the quantity then we don't use a
    // fieldset so we want to set a title here.
    $element['#title'] = $filter ? _webform_filter_xss($component['name']) : $component['name'];
  }
  return $element;
}