By slandry-2 on
I'm wondering what the best approach for this would be.
I have a taxonomy that is a list of states and cities and a list of companies within that city. For example:
Massachusetts > Boston > Bank of America
What I would like to do is have other content owners add companies to list under "Boston" and have the new node automatically associated with the parent "Boston". When they are done adding a new company, it will be listed under Boston in the navigation.
Any thoughts?
Comments
Clarification..
Are you saying that the company name would also be a taxonomy term, or would the company node just be tagged with the city taxonomy term?
And from what kind of page will the users be coming from when they go to the node form? For example, will they be coming from a page like taxonomy/term/tid or will it be some custom content type page that you created? (I'm asking because there's different ways to dynamically extract the term ID from the URL, etc. when prepopulating the form.
The user would navigate from
The user would navigate from a Massachusetts page where there would be a list of cities, click on the link to Boston see the list of companies and have the opportunity to add an additional company.
Ideally I would like the company name to then extend the taxonomy. I want users to be able to add new content which could be a sibling or a child of a term but not associate it with a term in the taxonomy which is a parent or grandparent. Yes, dynamically extracting the term sounds like the best solution but I don't want the user to be able to change the term ID. Any thoughts on how to do that? Thanks!
What I'd Do
For the company content type, I'd add a content taxonomy field (or just regular taxonomy field if you so desire), but on that content type's template I wouldn't actually show that field to the user. You could, for example, create a "trash" variable that renders that form element before you render the rest of the form. Then, just don't actually print the contents of that trash variable. For example...
I'd use the Prepopulate module to populate the value of that field. It would take the term ID from the page it was linked from. (From where on the linking page it would get this info would depend on the type of page. For example, if the page is created with Views using views arguments, it could get the term ID from the URL. Or, if you have your own content type for these city listing pages, you could add a taxonomy field to those pages, selecting the appropriate city taxonomy term for each city listing page, and then base your prepopulate data on the data within that field).
As for the part about each company having its own child pages, etc., the easiest way to do this would be to add a node reference field on the child content types, which would reference the company. Then, the user wouldn't even have to select any taxonomy terms for the child page. You could still use code (node_load) to extract the associated company's taxonomy terms, though.
If you're set on actually having each company name be its own taxonomy term, though, you'd have to find a module that allows free tagging for specific taxonomy subsets. Content Taxonomy module might have this functionality, but I'm not too sure. Once you find a module that allows for this, you'd again use the Prepopulate module. There are 2 things you'd have to populate -- the parent term (the city; use the same prepopulating method as above) and the company name (unless you're a java/jQuery/whatever wizard and would know how to populate this field instantly as the user is filling in the company name, you'd probably have to code something into the company form's submit button function, taking the title's value and populating the company name taxonomy field with this value -- technically this wouldn't be "prepopulating" so you wouldn't need to use the Prepopulate module for this aspect of it, but you'd still need that module nonetheless to prepopulate the parent term aspect).
_
If you use the content_taxonomy module, there's an option to store the entire taxonomy tree (not just the bottom term) on the node. Works great.