? views_attach-399648.patch
Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_attach/README.txt,v
retrieving revision 1.1
diff -u -p -r1.1 README.txt
--- README.txt	13 Jan 2009 08:07:10 -0000	1.1
+++ README.txt	13 Mar 2009 12:00:06 -0000
@@ -21,6 +21,7 @@ REQUIREMENTS
 
 - Drupal 6
 - Views 2
+- Token
 
 AUTHOR AND CREDIT
 
@@ -29,3 +30,6 @@ Jeff Eaton "eaton" (http://drupal.org/us
 
 Maintainer:
 Larry Garfield "Crell" (http://drupal.org/user/26398)
+
+Token integration:
+Alexander Makarov "Sam Dark" (http://drupal.org/user/281132)
\ No newline at end of file
Index: views_attach.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_attach/views_attach.info,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 views_attach.info
--- views_attach.info	20 Jan 2009 21:19:48 -0000	1.1.2.1
+++ views_attach.info	13 Mar 2009 12:00:06 -0000
@@ -3,4 +3,5 @@ name = Views attach
 description = Provides new Views display types that can be attached to nodes or users. 
 core = 6.x
 dependencies[] = views
+dependencies[] = token
 package = Views
Index: views_attach.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_attach/views_attach.module,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 views_attach.module
--- views_attach.module	22 Feb 2009 23:05:36 -0000	1.1.2.7
+++ views_attach.module	13 Mar 2009 12:00:08 -0000
@@ -50,7 +50,21 @@ function views_attach_user($op, &$edit, 
       foreach ($views as $info) {
         $view = views_get_view($info['name']);
         $view->set_display($info['display']);
-        $args = $view->display_handler->get_option('default_argument') === 'uid' ? array($account->uid) : array();
+
+		//TODO: check
+		// we will need taxonomy and cck for sure
+		$token_string = $view->display_handler->get_option('default_argument');
+
+		$user = user_load($account->uid);
+
+		if($user){
+			$args = get_arguments_from_token_string($token_string, 'user', $user);
+		}
+		else {
+			//TODO: is this possible not to get user by $account->uid?
+			$args = array();
+		}
+
         $result = $view->execute_display($info['display'], $args);
         if (!empty($result)) {
           $account->content[$view->name . '_' . $info['display']] = array(
@@ -91,7 +105,12 @@ function views_attach_nodeapi(&$node, $o
       foreach ($views as $info) {
         $view = views_get_view($info['name']);
         $view->set_display($info['display']);
-        $args = $view->display_handler->get_option('default_argument') === 'nid' ? array($node->nid) : array();
+
+		//TODO: check
+		$token_string = $view->display_handler->get_option('default_argument');
+
+		$args = get_arguments_from_token_string($token_string, 'node', $node);
+
         $result = $view->execute_display($info['display'], $args);
         if (!empty($result)) {
           // This is not really a form item, but by using item here we get
@@ -220,4 +239,21 @@ function views_attach_build_modes() {
     );
   }
   return $modes;
+}
+
+/**
+ * Get view arguments array from string that contains tokens
+ *
+ * @param string $string
+ * @return array
+ *
+ * @todo: security?
+ */
+function get_arguments_from_token_string($string, $type, $object){
+	$args = trim($string);
+
+	if(empty($args)) return array();
+		
+	$args = token_replace($args, $type, $object);
+	return explode('/', $args);
 }
\ No newline at end of file
Index: views_attach_plugin_display_node_content.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_attach/views_attach_plugin_display_node_content.inc,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 views_attach_plugin_display_node_content.inc
--- views_attach_plugin_display_node_content.inc	22 Feb 2009 23:05:36 -0000	1.1.2.7
+++ views_attach_plugin_display_node_content.inc	13 Mar 2009 12:00:14 -0000
@@ -10,7 +10,8 @@ class views_attach_plugin_display_node_c
 
     $options['types'] = array('default' => array());
     $options['modes'] = array('default' => array('full'));
-    $options['default_argument'] = array('default' => 'nid');
+	//TODO: is this correct?
+    $options['default_argument'] = array('default' => '');
     $options['show_title'] = 0;
 
     return $options;
@@ -57,6 +58,7 @@ class views_attach_plugin_display_node_c
       $weight = 10;
     }
 
+	//TODO: rename "argument" to "arguments string"?
     $default_argument = $this->get_option('default_argument');
     $options['default_argument'] = array(
       'category' => 'node_content',
@@ -104,10 +106,25 @@ class views_attach_plugin_display_node_c
       case 'default_argument':
         $form['#title'] .= t('Default argument');
         $form['default_argument'] = array(
-          '#type' => 'checkbox',
-          '#title' => t('Provide the current node id as a default argument.'),
-          '#default_value' => $this->get_option('default_argument') === 'nid',
-          '#return_value' => 'nid',
+          '#type' => 'textfield',
+          '#default_value' => $this->get_option('default_argument'),
+		  '#description' => 'Separate arguments with "/".',
+        );
+
+		// TODO: add other object types?
+
+		$base_table = $form_state['view']->base_table;
+
+		switch ($base_table){
+			case 'users':
+				$node_type = 'user';
+			break;
+			default:
+				$node_type = 'node';
+		}
+
+		$form['help'] = array(
+			'#value' => theme('token_help', $node_type)
         );
         break;
 
@@ -131,8 +148,7 @@ class views_attach_plugin_display_node_c
         $this->set_option('types', array_filter($form_state['values']['types']));
         break;
       case 'modes':
-        $this->set_option('modes', array_values(array_filter($form_state['values']['modes'])));
-        break;
+        $this->set_option('modes', $form_state['values']['modes']);
       case 'default_argument':
         $this->set_option('default_argument', $form_state['values']['default_argument']);
         break;
