New page with Panels variation.
Context - logged in user
Relationship - Node from User (on node.node_author)

Notice: Undefined index: relationship_entity_from_schema:uid-user-node_1 in theme_ctools_context_list() (line 233 of /Applications/MAMP/htdocs/mysite/sites/all/modules/ctools/includes/

Now here is the thing, if I have a node with a nid that matches my uid (If I'm logged in as user 1, and a node 1 exists) there is no error. But if I delete node 1, and create node 2 (authored by uid 1), I see an error, and the list of fields at the bottom does not display.

It seems to be trying to load a node, not by author at all, but by matching id... which is quite puzzling. Can anyone else give me some insight here?

After extensive debugging, I see the problem appear in ctools_context_create_entity(). In line 81 of it has:
$data = entity_load($entity_type, array($id));
Now, debugging these vars shows me that $entity type is 'node' and $id is the ID of the user that our relationship is based on... so we are trying to load a node by passing it a uid??

P.S. I'm only using nodes to explore and explain this issue - my real use case is an eck entity which is having exactly the same issues...

Members fund testing for the Drupal project. Drupal Association Learn more


Chris Gillis’s picture

If I hack this line in:
if($entity_type == 'node'){ $id = 2; }
The error disappears and I can see the fields...

jhodgdon’s picture

Several other people have noticed similar problems, and I've put notes on them that they're duplicates of this issue.

So the problem here is that in, the function theme_ctools_context_list() is trying to build the Relationships section of the contexts list, around line 230:

      if (isset($relationship['keyword'])) {
        $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $relationship['keyword']));
        foreach (ctools_context_get_converters('%' . $relationship['keyword'] . ':', $contexts[ctools_context_id($relationship, 'relationship')]) as $keyword => $title) {
          $desc .= '<br />' . t('@keyword --&gt; @title', array('@keyword' => $keyword, '@title' => $title));
        $desc .= '</div>';
      $output .= '<td>' . $desc . '</td>';
      $output .= '</tr>';
      $titles[ctools_context_id($relationship, 'relationship')] = $relationship['identifier'];

The problem is that there is an assumption that $contexts and $titles both have an entry corresponding to ctools_context_id($relationship, 'relationship'). But they don't. I don't think the relationships are making entries in $context at all actually. [Some of the reported errors from other issues are in the $contexts array and some are in the $titles array, but I think it's really the same problem]

I just ran into it with a custom plugin I am trying to write, and others have run into it with other types of plugins... I'm not sure I understand the code well enough to fix it though?

TheMGamer’s picture

bumb? This is important

TheMGamer’s picture

Version: 7.x-1.x-dev » 7.x-1.3
jhodgdon’s picture

Version: 7.x-1.3 » 7.x-1.x-dev

Do not change the version please. Yes the issue exists in 7.x-1.3, but it needs to be fixed in the development version.

TheMGamer’s picture

bumb? Can anyone help here? Important!

TheMGamer’s picture

Priority: Major » Critical
jhodgdon’s picture

We just ran into this issue again, and this time using a Relationship plugin provided by CTools.

The plugin is the generic "entity from schema" relationship plugin, and in this case, it was the "reverse" relationship that tries to find a Commerce Order from a User.

The error message this time is:
Notice: Undefined index: relationship_entity_from_schema:uid-user-commerce_order_1 in theme_ctools_context_list() (line 230 of /opt/www/deohs/sites/all/modules/contrib/ctools/includes/

Also, in this case after adding the relationship, it doesn't appear to work -- it doesn't show up, for instance, when I try to base a Selection Rule for a Panels Page on this relationship (for instance, using the "context exists" condition). That may be a separate issue, but then again it may not be.

Chris Gillis’s picture

Sorry I haven't been able to help. The client reconfigured their requirements so I don't need Panels anymore...

slucero’s picture

I'm experiencing the same issues described above except with a entity_from_field relationship provided by CTools. The use case is adding a context to capture an OG a user belongs to based on the og_user_node field on the user entity, but if the relationship is based off of the logged in user and the logged in user doesn't belong to a group then the call to ctools_entity_from_field_context() fails and doesn't load the context for the relationship. With this relationship context missing theme_ctools_context_list() fails resulting in the error below.

Notice: Undefined index: relationship_entity_from_field:og_user_node-user-node_1 in theme_ctools_context_list()

This instance of the error traces down to this block inside of ctools_entity_from_field_context():

if (isset($context->data->{$entity_info['entity keys']['id']})) {
    // Load the entity.
    $id = $context->data->{$entity_info['entity keys']['id']};
    $entity = entity_load($from_entity, array($id));
    $entity = $entity[$id];
    if ($items = field_get_items($from_entity, $entity, $field_name)) {
      if (isset($items[$delta])) {
        $to_entity_info = entity_get_info($to_entity);
        $plugin_info = ctools_get_relationship($conf['name']);
        $to_entity_id = $items[$delta][$plugin_info['source key']];

        // Send it to ctools.
        return ctools_context_create('entity:' . $to_entity, $to_entity_id);
      else {
        // In case that delta was empty.
        return ctools_context_create_empty('entity:' . $to_entity, NULL);

In the above code, the call to field_get_items() returns empty and fails the conditional which drops out of the function without any explicit return value. I'm not familiar enough with this code to know the ramifications of changing this section, but my initial thought is that the conditional should be adjusted such that an empty context is returned if no field items are found.

This instance of the error relates somewhat tangentially to the originally reported issue, but I expect this and the other related issues stem from similar logic throughout the context plugins.

TheMGamer’s picture

still getting the errors after applying the patch

slucero’s picture

I don't expect the patch posted in #10 to fix the issue, but rather serve as an example of the logic that may be the cause. That patch fixed the specific issue I was having and I expect similar fixes would be applicable in multiple places throughout CTools to address this and the other related issues.

TheMGamer’s picture


gillarf’s picture

Issue summary: View changes

I have a very similar issue.

I am trying to use a views content pane with a contextual filter based on a field from the user. It fails with a similar error message:

Notice: Undefined index: relationship_entity_from_field:field_diocese_reference-user-node_1 in theme_ctools_context_list() (line 230 of .../sites/all/modules/ctools/includes/

dajjen’s picture

546 bytes

I have the same error as #10 and here is a patch for (today) latest ctools.

kopeboy’s picture

Any update?

This is more than critical, we basically cannot create any page/view that needs to get a content from the logged in user, are we kidding?!

I get that exact error (thrown twice) on every brand new panel page (variant) when adding Context of ANY type and then trying to add a Relationship of ANY type from that context. I tried comments, profiles, content, user etc. and after Update & save I always get this error twice:

Notice: Undefined index: relationship_term_from_node_1 in theme_ctools_context_list() (line 230 of /srv/bindings/8036422060ee456b87e0ee13c0f08bad/code/sites/all/modules/ctools/includes/

I tried updating to last dev too (I was on 1.4) and no changes.

I tried to apply the patch from #15 and now the error is gone when adding Context: Content and relationship User from content, but still present when trying to get content from User (e.g. logged in User).

Also, if a fix isn't found soon, do you think there is a workaround? I am quite sure I've used this relationship in the past with no errors, and I think this might be a problem like the one from the issue creator, related to a particular case of deletion of nodes/users from the site (all from UI in my case, nothing strange)/ If that is the case we might cancel the error (without fixing the problem) deleting some columns in the database...?

I have not the skills to do this by myself thought :/

Any help is greatly appreciated!

Chris Gillis’s picture

Status: Active » Needs work

So the way this works is that people change the "status" when they post a patch, or find a patch does or doesn't work. @kopeboy thanks for your feedback that patch #15 breaks on content from "User". Because it still needs work I'm marking it as "Needs Work". If someone posts a revised patch, go ahead and test it and let everyone know if it works for you. If a bunch of people all find that the patch works, we can mark it as RTBC and the module maintainer will consider committing it. The maintainer is busy and unlikely to look at this until there is an RTBC patch...

TheMGamer’s picture

Actually there is a work around. When you set up a new page, you need to add a url argument for the user if you are going to display anything for the user.

For example:
- If you want to display user comments you need to have a path like this: user/comments/%uid or anything else that includes %uid, then set the argument settings as needed and it will work.

I hope you understand what I mean.

TheMGamer’s picture

Set file path to contain argument(s):

Set the argument %uid:

Set some relationships (in my example this is user's comments):

Here is the result:

kopeboy’s picture

Thank you for the workaround. It works, but I don't like it.

The problem is I cannot set normal menu links with arguments like that :/

I would have to install menu token (dev version with a patch on a production site, because translation is still buggy) and configure it. So basically I have another "filter" on any page that makes the site slower (correct me if I'm wrong, I am a noob here).

PS: so bad the maintainers won't help on a Critical Bug report

PapaGrande’s picture

I was getting this error too with my relationship plugin and the problem was that my plugin was returning FALSE when unable to get an identifier instead of an empty context. So a fix would be something like this:

   // Bail if we don't get a nid.
   if (!$my_nid = $my_items[0]['target_id']) {
-    return FALSE;
+    return ctools_context_create_empty('my_context', NULL);
  // Pass my nid to my context.
  return ctools_context_create('my_context', $my_nid);
Kingdutch’s picture

The reason this issue occurs is that a relationship's context is retrieved but there is data present for the 'from entity' which is then treated as the identifier to load the 'to entity'.

A scenario where this will fail:
Attempt to load the orders for a user when there are no orders created yet and the visiting user is admin (uid = 1). The relationship for Commerce Order will now be loaded with data containing uid 1. This happens in ctools_context_create_entity (ctools/plugins/contexts/ line 57) because data is not set.

The proper way to load relationships with non-existant data such as in the scenario above is to use ctools_context_create_empty which could happen in ctools_entity_from_schema_context (ctools/plugins/relationships/ line 120). However the if statement there does not catch this situation and thus it falls through to try to create a context with data.

The fix I used which feels like it's not the correct one and might have unwanted side effects as as follows. I unfortunately do not understand the intended logic well enough to dare touch the referenced guard clause for ctools_context_create_empty.

At line 132 of ctools/plugins/relationships/ where it says // Send it to ctools replace the return statement below that by:

$with_data = ctools_context_create('entity:' . $to_entity, $to_entity_id);

if (isset($with_data)) {
  return $with_data;

return ctools_context_create_empty('entity:' . $to_entity, NULL);

A rewording of the problem could actually be that the $to_entity_id is in practice the from_entity_id. However the scenario where the to_entity_id doesn't exist or isn't set is never handled (as referenced to earlier in my comment).

Although the above is a description and a workaround for the problem described in the issue, I just realised that at least in my case I was trying to load a 1 to many relationship (a user has many orders). Which of course isn't really possible without additional logic specifying which of those orders should be loaded. This suggests I should probably utilise a view for this scenario that loads the required order(s) for the user and thus the user is the only needed context.