I have an atom reference (image) field on a content type with "unlimited" values selected. An example node has 4 images on it.

I'm building a View for export of this data to XML. I have a relationship to the "Photos" field so I can get access to the "Atom: Scald ID". But the "Multiple Field Settings" section in the Views configuration is missing. So when Views creates the output it makes 4 separate rows, one for each image on that node.

In instances like this you can normally enable the "Display all values in the same row" option in "Multiple Field Settings" which will combine the values with a separator.

CommentFileSizeAuthor
#2 views-multiple-fields-2161131-2.patch4.35 KBnagy.balint
missing-6.jpg155.54 KBAnonymous (not verified)
multiple_field_settings-2.jpg71.43 KBAnonymous (not verified)

Comments

xenophyle’s picture

Replacing atom_reference_field_views_data() with the following code goes most or all of the way.

/**
 * Implements hook_field_views_data().
 */
function atom_reference_field_views_data($field) {
  $data = field_views_field_default_views_data($field);
  $entity_info = entity_get_info('scald_atom');
  foreach ($data as $table_name => $table_data) {
    if (isset($entity_info['base table'])) {
      $entity = $entity_info['label'];
      if ($entity == t('Node')) {
        $entity = t('Content');
      }

      $field_name = $field['field_name'] . '_sid';
      $parameters = array('@entity' => $entity, '!field_name' => $field['field_name']);
      $data[$table_name][$field_name]['relationship'] = array(
        'handler' => 'views_handler_relationship',
        'base' => $entity_info['base table'],
        'base field' => $entity_info['entity keys']['id'],
        'label' => t('@entity referenced from !field_name', $parameters),
        'group' => t('Atom Reference'),
        'title' => t('Referenced Atom'),
        'help' => t('A bridge to the @entity that is referenced via !field_name', $parameters),
      );
    }
  }

  return $data;
}


/**
 * Implements hook_field_views_data_views_data_alter().
 *
 * Views integration to provide reverse relationships on entityreference fields.
 */
function atom_reference_field_views_data_views_data_alter(&$data, $field) {
  foreach ($field['bundles'] as $entity_type => $bundles) {
    $target_entity_info = entity_get_info('scald_atom');
    if (isset($target_entity_info['base table'])) {
      $entity_info = entity_get_info($entity_type);
      $entity = $entity_info['label'];
      if ($entity == t('Node')) {
        $entity = t('Content');
      }
      $target_entity = $target_entity_info['label'];
      if ($target_entity == t('Node')) {
        $target_entity = t('Content');
      }

      $pseudo_field_name = 'reverse_' . $field['field_name'] . '_' . $entity_type;
      $replacements = array('@entity' => $entity, '@target_entity' => $target_entity, '!field_name' => $field['field_name']);
      $data[$target_entity_info['base table']][$pseudo_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'] . '_sid',
        'base' => $entity_info['base table'],
        'base field' => $entity_info['entity keys']['id'],
        'label' => t('@entity referencing @target_entity from !field_name', $replacements),
        'group' => t('Atom Reference'),
        'title' => t('Referencing atom'),
        'help' => t('A bridge to the @entity that is referencing @target_entity via !field_name', $replacements),
        'join_extra' => array(
          0 => array(
            'field' => 'entity_type',
            'value' => $entity_type,
          ),
          1 => array(
            'field' => 'deleted',
            'value' => 0,
            'numeric' => TRUE,
          ),
        ),
      );
    }
  }
}
nagy.balint’s picture

StatusFileSize
new4.35 KB

Here is the patch version.

Any review welcome.

nagy.balint’s picture

Status: Active » Needs review