It would be nice to have the entity reference support in ctools page manager's contexts panel like Relationships.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Damien Tournoud’s picture

Thanks for reporting this. Yes, I would like to see this happen. Should be relatively easy (look at the existing relationships in CTools for inspiration). Patches welcome!

BenK’s picture

Subscribing

Itangalo’s picture

I can only agree with Damien and others, this would be great. :-)

Shadlington’s picture

Subbing

mansspams’s picture

This should not be hard at all. What kind of entity reference support we need? Normal and reverse? Or more kinds? Some interface mockups would be helpful.

Itangalo’s picture

@mansspams: Just normal would be fine, if reverse are included it would be awesome. For multiple-value fields, the normal approach (so far) has been to pick the first value – so I guess that would be good in this case as well.

Taxoman’s picture

+1

das-peter’s picture

Status: Active » Needs review
FileSize
8.16 KB

I just looked into ctools/plugins/relationships/entity_from_field.inc and the attached patch is basically just a copy&paste of it - with some small modifications.

First tests look promising - would be great if someone else could give this a try / review.

Damien Tournoud’s picture

Thanks das-peter! This looks great.

+  // Get the settings for every entityreference field.
+  $fields_info = field_read_fields(array('type'=>'entityreference'));
+  foreach ($fields_info as $field_name => $field_info) {
+    $to_entity = $field_info['settings']['target_type'];
+    $to_entity_info = entity_get_info($to_entity);
+
+    $instances = field_read_instances(array('field_name' => $field_name));

Any reason why those don't use field_info_field() and field_info_instance()? The read versions are uncached and kind of internal to the Field API.

das-peter’s picture

The idea behind using field_read_fields() instead field_info_fields() was to be able to fetch all fields with the field type entityreference.
With field_info_fields() we need to iterate over all existing fields.
And to use field_info_field() we need to know the field name - but how could we without using field_read_fields() / field_info_fields()?

But I definitely wasn't aware that field_read_fields() is uncached - looks like this comes down to a simple question of performance. If iterating over all existing fields is faster than the field_read_fields() we should change the code.
Or is there even another way to get the all fields of a specified field type?

amateescu’s picture

Just wanted to let you know that I posted a patch for ctools that implements this functionality: #1315046: Add tools to help find all field definitions of a specified field type.. Earl said on IRC that he's ok with it, but I guess an extra review can't hurt :)

das-peter’s picture

Indeed that would be a handy function.
However, since we're mainly talking about performance here (if I didn't miss something) I'd go directly with an own loop ;)

amitaibu’s picture

Oh my, how did I miss this issue :/ -- #1340748: Add CTools relationship

Damien Tournoud’s picture

Can anyone clarify the relationship between this and #1340748: Add CTools relationship?

Damien Tournoud’s picture

Status: Needs review » Closed (duplicate)

Ok, duplicating this in favor of #1340748: Add CTools relationship.

sirviejo’s picture

Status: Closed (duplicate) » Needs review

Status: Needs review » Needs work

The last submitted patch, entityreference-add-ctools-relationships-1258502-8.patch, failed testing.

amateescu’s picture

Status: Needs work » Closed (duplicate)

Wtf?