function commerce_product_reference_views_data_alter in Commerce Core 7
Implements hook_views_data_alter().
File
- modules/
product_reference/ includes/ views/ commerce_product_reference.views.inc, line 44
Code
function commerce_product_reference_views_data_alter(&$data) {
// Add a node filter that filters by node types with product reference fields.
$data['node']['is_product_display'] = array(
'title' => t('Product display'),
'help' => t('Whether or not the content functions as a product display.'),
'real field' => 'type',
'filter' => array(
'handler' => 'commerce_product_reference_handler_filter_node_is_product_display',
'label' => t('Is a product display'),
'type' => 'yes-no',
),
);
// Add the node filter that filters by node types with product reference fields.
$data['node']['product_display_node_type'] = array(
'title' => t('Product display content type'),
'help' => t('Filters by the content type but only shows product display content types as options.'),
'real field' => 'type',
'filter' => array(
'handler' => 'commerce_product_reference_handler_filter_node_type',
),
);
// Add the line item filter for filtering by line items of a product line item
// type (based on $line_item_type['product']).
$data['commerce_line_item']['product_line_item_type'] = array(
'title' => t('Line item is of a product line item type'),
'help' => t("Filter line items to those of a product line item type (including but not limited to the default Product line item type)."),
'filter' => array(
'handler' => 'commerce_product_reference_handler_filter_product_line_item_type',
),
);
// Adds inverse relationships between the product and entity types referencing
// it (for example, nodes).
foreach (commerce_info_fields('commerce_product_reference') as $field_name => $field) {
foreach ($field['bundles'] as $entity_type => $bundles) {
if ($entity_type == 'commerce_line_item') {
continue;
}
$entity_info = entity_get_info($entity_type);
$replacements = array(
'@entity_type' => $entity_info['label'],
'!field_name' => $field['field_name'],
);
$data['commerce_product'][$field['field_name']]['relationship'] = array(
'handler' => 'views_handler_relationship_entity_reverse',
'field_name' => $field['field_name'],
'field table' => _field_sql_storage_tablename($field),
'field field' => $field['field_name'] . '_product_id',
'base' => $entity_info['base table'],
'base field' => $entity_info['entity keys']['id'],
'label' => t('@entity_type referencing products from !field_name', $replacements),
'title' => t('Referencing @entity_type', $replacements),
'help' => t('Relate a product to the @entity_type referencing it through !field_name.', $replacements),
'join_extra' => array(
0 => array(
'field' => 'entity_type',
'value' => $entity_type,
),
1 => array(
'field' => 'deleted',
'value' => 0,
'numeric' => TRUE,
),
),
);
}
}
}