I've been trying to create a list of users based on a set of fields in their user profile. If I create a User view, I can add the standard fields contained within the user profile (name, email, etc), but no added fields. It throws up the error dialog shown in the attached image. I expect this is linked to an existing issue with the Fields API, but none seemed to match precisely.

I'm running the latest development versions of Core and 7.x-3.x-dev (updated late on Dec. 23), with PHP 5.2.14, MySQL 5.1.51.

Comments

dawehner’s picture

Status: Active » Fixed

Please update to a recent version of ctools.

rosborn’s picture

Thanks - That was the one module where I was still using an alpha version. That has fixed the immediate error, but my non-standard fields are still not being displayed, although I can now edit all their properties.

bojanz’s picture

Status: Fixed » Postponed (maintainer needs more info)

What is a non-standard field?
A text/numeric field added via Fields UI?
Or a field whose type is defined by a contrib module (yours, perhaps)?

Can you give me a screenshot of the devel load node output (I want to see the structure of the fields not displayed).

rosborn’s picture

StatusFileSize
new68.38 KB
new15.19 KB
new40.37 KB
new106.67 KB

My PHP isn't up to creating my own modules yet. I created text and term reference fields using the "Manage Fields" tab of the Account settings admin page (see screenshot). I then added the fields to the Views fields output (screenshot), but only the standard "User" fields show up in the preview (screenshot).

I am attaching the Devel Load output screenshot for one of the user pages, with one of the fields (field_phone) expanded. The fields show up without problem on the user pages themselves.

The MySQL query is here:
---
SELECT field_data_field_staff.entity_id AS field_data_field_staff_entity_id, field_data_field_staff.entity_type AS field_data_field_staff_entity_type, field_data_field_staff.delta AS field_data_field_staff_delta, field_data_field_staff.language AS field_data_field_staff_language, field_data_field_staff.field_staff_tid AS field_data_field_staff_field_staff_tid, users.picture AS users_picture, users.uid AS uid, users.name AS users_name, users.mail AS users_mail, field_data_field_profile.entity_id AS field_data_field_profile_entity_id, field_data_field_profile.entity_type AS field_data_field_profile_entity_type, field_data_field_profile.delta AS field_data_field_profile_delta, field_data_field_profile.language AS field_data_field_profile_language, field_data_field_profile.field_profile_value AS field_data_field_profile_field_profile_value, field_data_field_profile.field_profile_format AS field_data_field_profile_field_profile_format, field_data_field_phone.entity_id AS field_data_field_phone_entity_id, field_data_field_phone.entity_type AS field_data_field_phone_entity_type, field_data_field_phone.delta AS field_data_field_phone_delta, field_data_field_phone.language AS field_data_field_phone_language, field_data_field_phone.field_phone_value AS field_data_field_phone_field_phone_value, field_data_field_phone.field_phone_format AS field_data_field_phone_field_phone_format FROM {users} users INNER JOIN {users_roles} users_roles ON users.uid = users_roles.uid LEFT JOIN {field_data_field_staff} field_data_field_staff ON users.uid = field_data_field_staff.entity_id AND (field_data_field_staff.entity_type = :views_join_condition_0 AND field_data_field_staff.deleted = :views_join_condition_1) LEFT JOIN {field_data_field_profile} field_data_field_profile ON users.uid = field_data_field_profile.entity_id AND (field_data_field_profile.entity_type = :views_join_condition_2 AND field_data_field_profile.deleted = :views_join_condition_3) LEFT JOIN {field_data_field_phone} field_data_field_phone ON users.uid = field_data_field_phone.entity_id AND (field_data_field_phone.entity_type = :views_join_condition_4 AND field_data_field_phone.deleted = :views_join_condition_5) WHERE (( (users_roles.rid IN ('4')) )) ORDER BY field_data_field_staff_field_staff_tid ASC, users_name ASC
----
Hope this all helps.

rosborn’s picture

Status: Postponed (maintainer needs more info) » Active

I just realized that I probably need to make this active again, now that I have provided extra information. Still new to this game.

I'm afraid that I haven't tested this with any Dev versions since Dec. 24, and I probably can't now until D7 is finally released since I don't want to break my site.

dawehner’s picture

If you use drupal7 on your live site you should have a development setup. Therfore clone your drupal files + drupal database and setup your drupal somewhere else.

There you can experiment/test current versions/test your changes.

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new4.01 KB

* Can reproduce the problem.
* Here is a fix.

dawehner’s picture

StatusFileSize
new4.1 KB

This is a much better patch.

bojanz’s picture

+        if (!isset($bundle)) {
+          // Some entity types doesn't have bundles so field_info_instances behaves different.
+          $instances = $instances[$entity_type];
+        }
+

We don't need that (in fact, it won't work if we are passing $entity_type).
That is done automatically by field_info_instances:

function field_info_instances($entity_type = NULL, $bundle_name = NULL) {
  $info = _field_info_collate_fields();
  if (!isset($entity_type)) {
    return $info['instances'];
  }
  if (!isset($bundle_name)) {
    return $info['instances'][$entity_type];
  }
  if (isset($info['instances'][$entity_type][$bundle_name])) {
    return $info['instances'][$entity_type][$bundle_name];
  }
  return array();
}

The actual fix is in passing bundle as NULL, and not as empty string, allowing the code above to work correctly.

bojanz’s picture

StatusFileSize
new747 bytes

Let's try just this :)

dawehner’s picture

StatusFileSize
new3.91 KB

Oh

        if (empty($entity_info[$name]['entity keys']['bundle']) && empty($entity_info[$name]['bundles'])) {
          $entity_info[$name]['bundles'] = array($name => array('label' => $entity_info[$name]['label']));
        }

in entity_get_info();

Here is a new patch based on this.

dawehner’s picture

@bojanz

When you just set the $bundle = NULL it fails with a php error :(

bojanz’s picture

Yeah, I didn't realize it still keyed it by $entity_type if there was no $bundle. Sorry!

#11 looks fine.
I'd change this comment:

// Entities without a bundle has $entity_type as $bundle name.

to

// Entities without a bundle have $entity_type as $bundle name.

But that can be done before commit, and after rosborn confirms this works for him :)

dawehner’s picture

StatusFileSize
new3.91 KB

Here is a new patch.

rosborn’s picture

That's impressive. Just applied the #14 patch, and now all my fields show up as requested.

Thanks for getting this fixed so quickly.

bojanz’s picture

Status: Needs review » Reviewed & tested by the community
dawehner’s picture

Status: Reviewed & tested by the community » Fixed

Thanks

Commited to the 7.x-3.x branch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.