with last commit: contrib field_collection mod & custom showroom et translator mods
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views integration for field collection fields.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_field_views_data().
|
||||
*
|
||||
* Adds a relationship to the default field data.
|
||||
*
|
||||
* @see field_views_field_default_views_data()
|
||||
*/
|
||||
function field_collection_field_views_data($field) {
|
||||
$data = field_views_field_default_views_data($field);
|
||||
$field_name = $field['field_name'];
|
||||
|
||||
if (isset($data['field_data_' . $field_name])) {
|
||||
$data['field_data_' . $field_name][$field_name . '_value']['relationship'] = array(
|
||||
'handler' => 'field_collection_handler_relationship',
|
||||
'base' => 'field_collection_item',
|
||||
'base field' => 'item_id',
|
||||
'label' => t('field collection item from !field_name', array('!field_name' => $field['field_name'])),
|
||||
'field_name' => $field['field_name'],
|
||||
);
|
||||
$data['field_revision_' . $field_name][$field_name . '_revision_id']['relationship'] = array(
|
||||
'handler' => 'field_collection_handler_relationship',
|
||||
'base' => 'field_collection_item_revision',
|
||||
'base field' => 'revision_id',
|
||||
'label' => t('field collection item revision from !field_name', array('!field_name' => $field['field_name'])),
|
||||
'field_name' => $field['field_name'],
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($field['bundles'] as $entity_type => $bundles) {
|
||||
$entity_info = entity_get_info($entity_type);
|
||||
$pseudo_field_name = $field['field_name'] . '_' . $entity_type;
|
||||
|
||||
list($label, $all_labels) = field_views_field_label($field['field_name']);
|
||||
$entity = $entity_info['label'];
|
||||
if ($entity == t('Node')) {
|
||||
$entity = t('Content');
|
||||
}
|
||||
|
||||
$data['field_collection_item'][$pseudo_field_name]['relationship'] = array(
|
||||
'title' => t('Entity with the @field (@field_name)', array('@entity' => $entity, '@field' => $label, '@field_name' => $field['field_name'])),
|
||||
'help' => t('Relate each @entity using @field.', array('@entity' => $entity, '@field' => $label)),
|
||||
'handler' => 'views_handler_relationship_entity_reverse',
|
||||
'field_name' => $field['field_name'],
|
||||
'field table' => _field_sql_storage_tablename($field),
|
||||
'field field' => $field['field_name'] . '_value',
|
||||
'base' => $entity_info['base table'],
|
||||
'base field' => $entity_info['entity keys']['id'],
|
||||
'label' => t('!field_name', array('!field_name' => $field['field_name'])),
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provide relationship handler for field collection fields.
|
||||
*/
|
||||
class field_collection_handler_relationship extends views_handler_relationship {
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['delta'] = array('default' => -1);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a delta selector for multiple fields.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$field = field_info_field($this->definition['field_name']);
|
||||
|
||||
// Only add the delta selector if the field is multiple.
|
||||
if ($field['cardinality']) {
|
||||
$max_delta = ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) ? 10 : $field['cardinality'];
|
||||
|
||||
$options = array('-1' => t('All'));
|
||||
for ($i = 0; $i < $max_delta; $i++) {
|
||||
$options[$i] = $i + 1;
|
||||
}
|
||||
$form['delta'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#default_value' => $this->options['delta'],
|
||||
'#title' => t('Delta'),
|
||||
'#description' => t('The delta allows you to select which item in a multiple value field to key the relationship off of. Select "1" to use the first item, "2" for the second item, and so on. If you select "All", each item in the field will create a new row, which may appear to cause duplicates.'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function ensure_my_table() {
|
||||
$field = field_info_field($this->definition['field_name']);
|
||||
|
||||
if (!isset($this->table_alias)) {
|
||||
$join = $this->get_join();
|
||||
if ($this->options['delta'] != -1 && $field['cardinality']) {
|
||||
$join->extra[] = array(
|
||||
'field' => 'delta',
|
||||
'value' => $this->options['delta'],
|
||||
'numeric' => TRUE,
|
||||
);
|
||||
}
|
||||
$this->table_alias = $this->query->add_table($this->table, $this->relationship, $join);
|
||||
}
|
||||
return $this->table_alias;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user