I am creating a Product Registry database where individual companies submit products for review. Each company has multiple products, each product has multiple 'attributes' that have to be tested. I have a fix for keeping the forms under Company/OG scope by hooking into the pageroute API and adding information to the Route->Option array - (ie: Fago's recommendation to og_set_group_context). The modification is easily done by adding a query to the URL ?gid=<>, and I built the link automatically using Drupal Tool.

Now, the next HUGE hurdle. We start with 2 forms, the first for the parent 'Product information' node, then the 2nd Node Mgmt form for attributes. I am going to have to filter that form so it will only list children attributes for the product information form in the previous page. I don't have much time, so if necessary I will be modifying Pageroute to do that.

Nodefamily is not going to work in this application, because different people can post Products and Product attributes. So I am using Relativity instead. It stores relationships in table 'relativity', so I can get what I need to filter out unwanted Attributes by parent product NID.

In lieu of a patch by the end of the day (that's impossible, RIGHT? ), some improvement in the Custom Page-types would be really helpful.

Custom page-types offer a more modular way to make the fix, but the documentation isn't complete enough for me to successfully do this. In lieu of a fix, it would be very helpful if one of you can add more content to
http://drupal.org/node/310810. I need to know what files or kind of file each snippet of code goes into, and how that really relates to what is in pageroute_pages.inc.

Another couple of comments about the documentation. I did not see pageroute.pages.inc in pageroute, yet the author was asking me to create a new file with no basis for comparison - a very scary proposition at 3AM the day of a big demo.

Also, is the Subclass code supposed to be in your custom *.module file? Or is everything in the <>_page_<>.inc file? If so, where is it included? Your custom *.module file?

The code snippets were very nice, but they're not as useful as they can be because they need to include a file, or type of filename to be put into.

If you can do this, I can make the changes the modular way, and share them with you.

Here is the custom module code to implement Organic Group Scoping for Pageroute. There was no elegant solution to identifying the parent for a new child, I used a session array item that can only be filled in by the parent content-type.

<?php

// $Id$

/**
* @file
* Custom coding for CHPS Product Registry Database
*
* @author
* Paul Wolborsky, Design2Market
*/

define('SUPPLIER_PRIMARY_USER_ROLE','supplier primary user');
define('SUPPLIER_SECONDARY_USER_ROLE','supplier secondary user');
define('SUPPLIER_THIRD_USER_ROLE','supplier third user');
define('SUPPLER_NEW_USER_ROLE','supplier new');
define('NEW_USER','new user');

define('CONTENT_TYPE_GROUP','Group');
define('CONTENT_TYPE_PRODINFO','production_prod_info_2');
define('CONTENT_TYPE_ATTRIBUTE','attributes');

function chpsform_pagerouteapi($op, &$a2, $a3) {
	switch ($op) {
		case 'show':
		$gid = $a2->route->options['gid'];

		if (!og_get_group_context()) {
			$group = node_load($gid);
			og_load_group($group);
			og_set_group_context($group);
		}
		break;
		
		case 'view':
		break;
	}
}

function chpsform_nodeapi(&$node, $op, $teaser, $page) {
	switch ($op) {
		case 'insert':
		if (empty($node->gid)) {
			$gid=0;
			if (isset($_REQUEST['gid'])) {
				$gid = $_REQUEST['gid'];
			}
			if (empty($gid) && !empty($node->nid)) {
				$sql = "SELECT og_ancestry.group_nid FROM {og_ancestry} WHERE og_ancestry.nid = '%s'";
				$results = db_query(db_rewrite_sql($sql), $node->nid);
				$gid = db_fetch_object($results);
			}
			if (!og_get_group_context() && !empty($gid)) {
				$group = node_load($gid);
				og_load_group(&$group); // gee, gid would be nice
				og_set_group_context($group);
			}
			$node->option['gid']=$gid;
			$node->option['parent']=$node->nid;

		}
		if ($node->type==CONTENT_TYPE_PRODINFO) {
			$node->parent_node = $gid;
			og_load_group(&$node); // gee, gid would be nice
			og_set_group_context($node);
//			og_save_ancestry($node);
//			relativity_addparent($node->nid, $gid);

			$sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public) VALUES (%d, %d, %d)";
//			echo "og_save_ancestry for nid->".$node->nid."< gid->".$gid."< sql->".$sql."< <br>";
		        db_query($sql, $node->nid, $gid, $node->og_public);

			$node->field_name['gid'][0]['value'] = $gid;
			$node->field_name['parent_nid'][0]['value'] = $gid;
			$_SESSION['product_parent'] = $node->nid;
		} else if ($node->type==CONTENT_TYPE_ATTRIBUTE) {
			/*
			 * This is a tough one.  This function should be called
			 * previously to act on the Product Information node before
			 * saving it to the database.  But now it is called to act
			 * on a node that has no memory of what has happened before,
			 * and should not.  So am using a session variable here.
			 *
			 * I will put in a feature request to the pageroute people to
			 * build in parentage.  Pageroute now is basically built for a
			 * collection of sibling nodes, but are moving in the family direction.
			 */
			$parent = $_SESSION['parent_parent'];
echo "ATTRIBUTES parent->".$parent."< <br />";
//			og_save_ancestry($node);
			$sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public) VALUES (%d, %d, %d)";
			echo "og_save_ancestry for nid->".$node->nid."< gid->".$gid."< sql->".$sql."< <br>";
		        db_query($sql, $node->nid, $gid, $node->og_public);
			relativity_addparent($node->nid, $parent);
echo "DID RELATIVITY<br>";
			$node->field_name['gid'][0]['value'] = $gid;
			$node->field_name['parent_nid'][0]['value'] = $parent;
		}
		break;
	}
}

?>

Comments

Tauran’s picture

Status: Active » Closed (fixed)

You were looking at the documentation for the drupal6 version!

For drupal5 look in the API.txt and README.txt provided with the module.

If you still experience problems start a new request please.