I have the same problem with views 2. I'm using a Views node as my front page and can't get the NID from a URL to populate node references. I was looking for the problem and discovered the note about API in context changing. I just copied the nodeapi function and created the helper.module with it as per instruction in creating the helper module. Then I disabled the views_arg_module. You don't have to do those two last steps! You can just change the views argument to the PHP code below. For the Views argument I selected Arguments -> Node: Nid -> Provide Default Argument -> PHP code -> added code below.
$context =(context_get());
if ($context) {
return $context['node']['nid'];
}
Here is the code I used to make the helper.module.
/**
* Implementation of hook_nodeapi
*
* (courtesy of sethcohn)
* Provides some out-of-the-box data to Views, and can be used as a template for
* exposing other data to Views via Context
*/
function helper_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
if ($op == 'view' && $page){
context_set('node', 'type', $node->type);
context_set('node', 'nid', $node->nid);
// avoid user 0 (anonymous), to avoid stray appearances during context
if ($node->uid) {
context_set('node', 'uid', $node->uid);
}
// less useful text items, more useful for theming than views... might be good for arg title usage though
context_set('node', 'name', $node->name);
context_set('node', 'title', $node->title);
}
}
These sound like two totally different issues to me.
Adam S, what version of Context are you using? Also, what do you mean about Context's API changing? I just looked up the most recent version of API.txt for that module and context_get and context_set have undergone no changes.
markdorison, I'll be releasing a new version for Views 3 very soon. The Views API for plugins has changed slightly since Views 2.x. I already have the new code working, I just need to set up a new branch of this module to hold it.
The issue is not Views 2 and Views 3. I think that context_set() has changed between Context 2 and Context 3. So working with Context 3 and Views 2 is the same as working with Context 3 and Views 3. "The argument options for namespace and attribute do not appear on the form" is not a problem of upgrading to Views 3, it's a problem of upgrading to Context 3.
I've been using this module in its current state with Context 3 and haven't had any difficulties whatsoever. Moreover, I've been using Context 3 on its own for months now, and context_set() is working just as it's always worked... maybe you can try to give me some more details to work with?
>I've been using this module in its current state with Context 3 and haven't had any difficulties whatsoever. Moreover, I've been using Context 3 on its own for months now, and context_set() is working just as it's always worked... maybe you can try to give me some more details to work with?
I had moved to Context 3 from Context 2 because I need to set context per anonymous user. It stopped working. Here is the solution to a problem I had . http://drupal.org/node/723792#comment-3121392
Is it apropriate to re-open this issue, or should a new one be created? I leave this unchanged, and hope someone will read this. My views page looks very much like the one of markdorison who started this issue.
This is not working on the current views 6.x-3.0-alpha3, and I also upgraded to views-6.x-3.x-dev, and had the same result. More info which might be needed. I am using the Pressflow 6.20.
Context:
drush pm-info context
Project : context
Type : module
Title : Context
Description : Provide modules with a cache that lasts for a single page request.
Version : 6.x-3.0
Package : Context
Core : 6.x
PHP : 4.3.5
Status : enabled
Path : sites/all/modules/context
Schema version : 6304
Requires : ctools
Views:
drush pm-info views
Project : views
Type : module
Title : Views
Description : Create customized lists and queries from your database.
Version : 6.x-3.0-alpha3
Package : Views
Core : 6.x
PHP : 4.3.5
Status : enabled
Path : sites/all/modules/views
Schema version : 6009
Requires : none
drush pm-info views_arg_context
Type : module
Title : Views Default Argument from Context
Description : Allows the default value for a Views argument to be specified through Context module data set using context_set.
Version : 6.x-1.x-dev
Package : Other
Core : 6.x
PHP : 4.3.5
Status : enabled
Path : sites/all/modules/views_arg_context
Schema version : module has no schema
Requires : views, context, ctools
Required by : none
I updated the code to reflect the changes in the Views 3 API. The fields were not appearing for me in Views 6.x-3.0-rc3. It looks like there were some changes between Views 2 and Views 3 in how options are declared in the Views UI.
Please ignore the patch above, it doesn't display the saved options in the Views UI after you enter values for namespace and attribute and return to edit the view. This patch appropriately fixes the issue.
Latest patch from #15 didn't work for me. Instead I use php code as default argument type, return context_get('namespace', 'attribute'); . As much as possible I don't want to store php code in database. Is there way to fix views_arg_context in views 3? Thanks!
Comments
Comment #1
Adam S commentedI have the same problem with views 2. I'm using a Views node as my front page and can't get the NID from a URL to populate node references. I was looking for the problem and discovered the note about API in context changing. I just copied the nodeapi function and created the helper.module with it as per instruction in creating the helper module. Then I disabled the views_arg_module. You don't have to do those two last steps! You can just change the views argument to the PHP code below. For the Views argument I selected Arguments -> Node: Nid -> Provide Default Argument -> PHP code -> added code below.
Here is the code I used to make the helper.module.
Comment #2
brynbellomy commentedThese sound like two totally different issues to me.
Adam S, what version of Context are you using? Also, what do you mean about Context's API changing? I just looked up the most recent version of API.txt for that module and context_get and context_set have undergone no changes.
markdorison, I'll be releasing a new version for Views 3 very soon. The Views API for plugins has changed slightly since Views 2.x. I already have the new code working, I just need to set up a new branch of this module to hold it.
Comment #3
brynbellomy commentedQuick update -- the 1.x-dev branch of this module should work with Views 3. Give it a whirl!
Comment #4
markdorisonbrynbellomy, Thanks! I will check it out.
Comment #5
Adam S commentedThe issue is not Views 2 and Views 3. I think that context_set() has changed between Context 2 and Context 3. So working with Context 3 and Views 2 is the same as working with Context 3 and Views 3. "The argument options for namespace and attribute do not appear on the form" is not a problem of upgrading to Views 3, it's a problem of upgrading to Context 3.
Comment #6
brynbellomy commentedI've been using this module in its current state with Context 3 and haven't had any difficulties whatsoever. Moreover, I've been using Context 3 on its own for months now, and context_set() is working just as it's always worked... maybe you can try to give me some more details to work with?
Comment #7
Adam S commented>I've been using this module in its current state with Context 3 and haven't had any difficulties whatsoever. Moreover, I've been using Context 3 on its own for months now, and context_set() is working just as it's always worked... maybe you can try to give me some more details to work with?
I had moved to Context 3 from Context 2 because I need to set context per anonymous user. It stopped working. Here is the solution to a problem I had . http://drupal.org/node/723792#comment-3121392
Comment #8
brynbellomy commentedComment #10
pkej commentedIs it apropriate to re-open this issue, or should a new one be created? I leave this unchanged, and hope someone will read this. My views page looks very much like the one of markdorison who started this issue.
This is not working on the current views 6.x-3.0-alpha3, and I also upgraded to views-6.x-3.x-dev, and had the same result. More info which might be needed. I am using the Pressflow 6.20.
Context:
Views:
views_arg_context 6.x-1.x-dev as per #3
Comment #11
pkej commentedI solved this by using "Default argument" -> PHP Code and added the code:
Comment #12
nicholas.alipaz commentedyes, it seems the fields for this module no longer show in views 3.
Comment #13
blisteringherb commentedI updated the code to reflect the changes in the Views 3 API. The fields were not appearing for me in Views 6.x-3.0-rc3. It looks like there were some changes between Views 2 and Views 3 in how options are declared in the Views UI.
Comment #14
markdorisonThis looks good to me.
Comment #15
blisteringherb commentedPlease ignore the patch above, it doesn't display the saved options in the Views UI after you enter values for namespace and attribute and return to edit the view. This patch appropriately fixes the issue.
Comment #16
xjmThere are some whitespace fixes needed here. (The trailing whitespace needs to be removed and there should be a newline at the end of the file.)
It'd be great to get some additional testing to confirm that this resolves the issue with Views 3 and does not break Views 2.
Comment #17
adriancruz commentedLatest patch from #15 didn't work for me. Instead I use php code as default argument type, return context_get('namespace', 'attribute'); . As much as possible I don't want to store php code in database. Is there way to fix views_arg_context in views 3? Thanks!
Comment #18
stoickthevast commentedHave the same concern like Adrian Cruz. As much as possible I dont want to store php code in DB. I created a patch for this issue.
Comment #19
xjmThanks @techwarrior and @adrian cruz. Can others test this patch for both Views 2 and Views 3 and confirm whether it resolves the issue?