Integrating custom types (with custom schema) with CCK

jbnewman's picture

I am currently producing a "family" of modules designed to manage a hosting infrastructure (email, dns, ftp, etc). I am cruising along, but keep coming back to one big stumbling block ... the role of CCK in my module. From a technical stand-point, I don't have a compelling need to use CCK (I'm happy to code up what needs to be coded), but it's clear that from a "best practice" perspective (and honestly, from a quality assurance & maintainability perspective), utilizing CCK as much as possible is a "good thing."

Among others, I have the following content types:

Email Address
Domain Resource Record (RR)

Each of these has a variety of different needs:

Customer is a dream. I built it up using CCK's UI and exported with Content Copy. All is good. Once I determine the best way to actually install the content as part of the module install, I'll be good. That said, I really would like to be able to define the content type name "on the fly." In other words, I know that installation A may already have a Client customer type that they'd like to use, instead of my (fairly basic) Customer type. Since I need to reference it in the node_access_records and node_grant hooks, I've got to know its name. But if I use variable_get, Coder really dislikes the concatenations...

Domain, Email Address, and Domain RR each are required to have a reasonably specific and static table structure... postfix, mydns, proftpd, etc., will be accessing the tables directly, in "real time". Therefore, not only do I have to limit joins as much as possible for performance, but I have to ensure the table structure is absolutely static. If an admin were to edit a field via the CCK UI in such a way that the schema changed ... his email server would go down. Which would probably be a "bad thing".

So, I build these all "by hand" in the module. (I saw passing reference somewhere to being able to use CCK, but override its schema, but I never figured out how one might go about that). In the grand scheme of things, rolling these into the module isn't all that big a deal; after all there are some specific needs that have to be addressed with each of them. (And by defining hook_content_extra_fields, I can make it minimally configurable via the UI). But then ... I get to Domain Resource Records. And guess what - it has to reference the domain. (Email Address I handled in a different way --- so, I didn't "cross this bridge" then). So, I need to add a nodereference field to my Domain RR content type.

I've spent way too many hours searching for a solution, and ultimately tried dumping this into my hook_form:

['domain_reference'] = array(
'#type' => 'nodereference_autocomplete',
'#title' => 'Domain (Zone)',
'#referenceable_types' => array ('host_domain' => 'host_domain'),
'#field_name' => 'domain_reference',

It seems to think about it -- I get a ": found no valid post with that title." error when I do a submit, but ... the autocomplete doesn't work, and I always get that error. Clearly I'm doing something wrong.

Ultimately, I have the following questions:

1.) When doing a "hybrid" model, where I'm adding CCK fields "on top" of a content type created into a module, are there any "best practices" to note? (For example, I add the customer nodereference to domain using Content Copy).

2.) What should I be doing to get this domain reference on the RR content type, in a way that it's stored in my set of database tables, not by CCK (as happens with the "hybrids").

There are absolutely a bunch of reasonably ugly work-arounds i can use, but I'm trying to "do this right." Your sage wisdom (or, perhaps, not so sage wisdom, I guess) is appreciated.