Comments

Adam S’s picture

Priority: Normal » Critical

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);
  }
}
brynbellomy’s picture

Status: Active » Postponed (maintainer needs more info)

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.

brynbellomy’s picture

Quick update -- the 1.x-dev branch of this module should work with Views 3. Give it a whirl!

markdorison’s picture

brynbellomy, Thanks! I will check it out.

Adam S’s picture

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.

brynbellomy’s picture

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?

Adam S’s picture

>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

brynbellomy’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

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

pkej’s picture

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

views_arg_context 6.x-1.x-dev as per #3

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
pkej’s picture

I solved this by using "Default argument" -> PHP Code and added the code:

return context_get('namespace', 'value');
nicholas.alipaz’s picture

Status: Closed (fixed) » Needs work

yes, it seems the fields for this module no longer show in views 3.

blisteringherb’s picture

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.

markdorison’s picture

Status: Needs work » Needs review

This looks good to me.

blisteringherb’s picture

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.

xjm’s picture

Priority: Critical » Major
+++ b/views_arg_context/plugins/views_plugin_argument_default_context.incundefined
@@ -10,29 +10,25 @@
 class views_plugin_argument_default_context extends views_plugin_argument_default {
   var $option_name = 'views_arg_context';
+  ¶

@@ -50,4 +46,15 @@ class views_plugin_argument_default_context extends views_plugin_argument_defaul
   }
+  ¶
+  function convert_options(&$options) {
...
 }
\ No newline at end of file

There 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.

adriancruz’s picture

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!

stoickthevast’s picture

Have 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.

xjm’s picture

Thanks @techwarrior and @adrian cruz. Can others test this patch for both Views 2 and Views 3 and confirm whether it resolves the issue?