protected function CommerceProductInlineEntityFormController::attributes in Inline Entity Form 7
Returns a list of field names that are used as attributes for the given product type.
3 calls to CommerceProductInlineEntityFormController::attributes()
- CommerceProductInlineEntityFormController::entityForm in includes/
commerce_product.inline_entity_form.inc - Overrides EntityInlineEntityFormController::entityForm().
- CommerceProductInlineEntityFormController::save in includes/
commerce_product.inline_entity_form.inc - Overrides EntityInlineEntityFormController::save().
- CommerceProductInlineEntityFormController::tableFields in includes/
commerce_product.inline_entity_form.inc - Overrides EntityInlineEntityFormController::tableFields().
File
- includes/
commerce_product.inline_entity_form.inc, line 305 - Defines the inline entity form controller for Commerce Products.
Class
- CommerceProductInlineEntityFormController
- @file Defines the inline entity form controller for Commerce Products.
Code
protected function attributes($type) {
// Attributes are tied to the commerce_cart module.
if (!module_exists('commerce_cart')) {
return array();
}
$attributes = array();
// Loop through all the field instances on that product type.
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']);
// Get the array of Cart settings pertaining to this instance.
$commerce_cart_settings = commerce_cart_field_instance_attribute_settings($instance);
// If the instance is of a field type that is eligible to function as
// a product attribute field and if its attribute field settings
// specify that this functionality is enabled...
if (commerce_cart_field_attribute_eligible($field) && $commerce_cart_settings['attribute_field']) {
$attributes[$name] = array(
'field' => $field,
'instance' => $instance,
'weight' => $instance['widget']['weight'],
);
}
}
// Sort the fields by weight.
uasort($attributes, 'drupal_sort_weight');
return $attributes;
}