Closed (fixed)
Project:
Chaos Tool Suite (ctools)
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
27 Oct 2010 at 20:28 UTC
Updated:
2 May 2017 at 08:07 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
merlinofchaos commentedHm. That error indicate sthat somehow a context object is being passed as not a context object. I'm not sure how that could happen. I've never seen that happen in my usage.
Perhaps content_profile is somehow returning something incorrect in one of its context/relationship plugins?
Comment #2
idcm commented@merlinofchaos, I have no idea. I just know the patch on that other issue thread worked. Is there a test I can do to help you get more information?
Comment #3
mstef commented+1.. getting this with ctools 1.8. I doubt that it's ctool's fault because the context class clearly has this function defined. I'm getting this in conjunction with og panels, which I have to assume is just too outdated.
Comment #4
Letharion commentedComment #5
megachrizI also encountered this bug. I could reproduce the bug in a fresh install too.
Steps to reproduce
1. Create three content types (group, album, song).
2. Enable modules Panels, Page manager and Chaos Tools.
3. Create a custom page (admin/structure/pages/add).
Form values:
Administrative title: songs per album per group
Path: node/%group/%album/%song
Optional features: Selection rules: active
4. On argument settings, set the following:
%group: Node: ID: group
%album: Node: ID: album
%song: Node: ID: song
5. On selection rules, add three "Node: type" criteria's and assign each node type. Longer explanation:
5.1 Add "Node: type".
5.2 In "Add criteria" popup, fill in the following values:
Node: group
Node type: Group
And click "Save".
5.3 Repeat steps 5.1 and 5.2 for "album" and "song" (instead of "group").
Now the Selection Rules page contains a table with three rows:
Title;Description;
Node: type;group is type "Group";
Node: type;album is type "Album";
Node: type;song is type "Song";
When you hit the button "Continue" now, the following error appears:
Fatal error: Call to undefined method stdClass::is_type() in /Websites/drupal/drupalsites/drupal7/sites/all/modules/contrib-standard/ctools/includes/context.inc on line 147
The path of the page is now:
admin/structure/pages/add/page-songs_per_album_per_group/criteria
Version information
PHP 5.3.2
Drupal 7.15
Install profile: Minimal
CTools 7.x-1.2
Panels 7.x-3.3
Other information
Tested as user 1.
Debug information
I went to debugging and found out that the error happens somewhere in the function
ctools_access_add_restrictions()or, in other words, this is the last function where the content of the parameters look still right.I think something is wrong with line 1579 in includes/context.inc:
In this code line,
$contextsgets overwritten with the result of thectools_context_select()call. I'm not sure whatctools_context_select()is supposed to return, because that is not documented.ctools_context_select()gets called three times:$contextsis an array of three ctools_context instances.ctools_context_select()returns a single ctools_context instance.$contextsis a single ctools_context instance.ctools_context_select()returns FALSE.$contextsis an instance of stdClass. A fatal error happens.I've attached some debug information, created with krumo using this code in the
ctools_access_add_restrictions()function:Comment #6
Jorrit commentedI have backtraced this to the following code from
context.inc:This method is invoked twice for the bundle argument. This is because the bundle argument is a restricting argument, as it adds information about the argument to the argument context.
The first time this code is executed, a single context is returned. This context ends up being the value of $contexts in
ctools_access_add_restrictions(). In the second invocation, theif (!is_array($contexts)) {part is triggered. Now$contextsis a numeric array, while in the first invocation it was an array keyed by the textual context id. The part$keys = array_keys($choices); $context = reset($keys);causes $context to become 0, triggeringif (empty($context) || empty($contexts[$context])) {. This causes$contextsto become false inctools_access_add_restrictions().Then, in
ctools_entity_bundle_ctools_access_restrictions(),$context->restrictions['type']is set without the code checking if$contextis an object. This causes$contextto become anstdClass.My solution is to change the above code snippet to:
Also,
ctools_access_add_restrictions()should check if$contexts = ctools_context_select($contexts, $required_context, $context);returns FALSE and not continue when it does.Comment #7
Jorrit commentedPlease see the attached patch.
Comment #8
Jorrit commentedMarking the right branch.
Comment #9
merlinofchaos commentedI'm not sure about #2. What if there's an empty array because there were no required contexts? There's at least one access rule like that.
Comment #10
Jorrit commentedYou mean hunk #2? Maybe it is better to check for
=== FALSE, you're right. Could you fix the parse error in the current 7.x-1.x-dev branch? All patches are now marked as Postponed because the branch they're based off is not testable. See #1300912: theme('advanced_help') has wrong parameters.Comment #11
Jorrit commentedUpdated patch
Comment #12
Renee S commentedThis (#11) fixed this problem for me. Haven't extensively tested but so far no weird side-effects, adding a few panels and doing routine config tasks... Thanks, @Jorrit!
Comment #13
mgimza2 commentedI resolved the problem by instantiating a new object of type ctools_context , passing the $type and $data as parameters:
foreach ((array) $contexts as $cid => $context_tmp) {
$context = new ctools_context($context_tmp->data->type,$context_tmp->data); //<- !! HERE !!
if ($context->is_type($this->keywords)) {
// Compare to see if our contexts were met.
if (!empty($this->restrictions) && !empty($context->restrictions)) {
foreach ($this->restrictions as $key => $values) {
...........
}
}
$result[$cid] = $context;
}
}
In the foreach loop I create a new instance of the ctools_context class with data from the $context_tmp StdClass which is taken from the $contexts array. In this way, the PHP interpreter knows about the "is_type()" function as it is defined in the ctools_context class.
It seems to me that PHP knows that $context is an StdClass , but not an object/class instance of type ctools_context.
I personally do not know the root cause. It may be a problem in the way the $contexts array is setup or the version of PHP that I am using PHP 5.3.
The same concept would be applied to this problem in any other part of the context.inc file.
I hope that this helps.
Comment #14
mgimza2 commentedI resolved the problem by instantiating a new object of type ctools_context , passing the $type and $data as parameters:
foreach ((array) $contexts as $cid => $context_tmp) {
$context = new ctools_context($context_tmp->data->type,$context_tmp->data); //<- !! HERE !!
if ($context->is_type($this->keywords)) {
// Compare to see if our contexts were met.
if (!empty($this->restrictions) && !empty($context->restrictions)) {
foreach ($this->restrictions as $key => $values) {
...........
}
}
$result[$cid] = $context;
}
}
In the foreach loop I create a new instance of the ctools_context class with data from the $context_tmp StdClass which is taken from the $contexts array. In this way, the PHP interpreter knows about the "is_type()" function as it is defined in the ctools_context class.
It seems to me that PHP knows that $context is an StdClass , but not an object/class instance of type ctools_context.
I personally do not know the root cause. It may be a problem in the way the $contexts array is setup or the version of PHP that I am using PHP 5.3.
The same concept would be applied to this problem in any other part of the context.inc file.
I hope that this helps.
Comment #15
loopduplicate commentedThis bug happened to me on a fresh install with the taxonomy module disabled. Enabling the taxonomy module fixed the problem. Hope that helps :)
Cheers,
Jeff
Comment #16
mradcliffeThe patch in #11 resolved the issue for me.
I developed a custom relationship plugin that loaded an og memberhip based on the required context of user. When I added the relationship, I could no longer visit the Selection Rules form due to this issue. Somehow the logged in user context was being half-created on the Selection Rules form.
Comment #17
Jorrit commentedThen I think we can consider this patch to be tested by the community.
Comment #18
japerry11 looks and tests good, especially with check from #10 included. Committed.
Comment #20
Jorrit commentedThanks for committing the patch and git attribution.
Comment #22
bfr commentedJust for future reference, in my case this was caused by missing Uid 0(anonymous user), something had removed it from the database. Adding it back fixed the problem: http://drupal.org/node/1029506