Noob question re: content types

Events happening in the community are now at Drupal community events on www.drupal.org.
WarrenK's picture

I want to create a custom content type in which I override the template for the content type generated when creating a content type using the usual "add content type". The content type generated the usual way has too much cruft that gets in the way of theming the content type using CSS.

I have read about and experimented with creating node template overrides using the node--mystuff.tpl.php convention but what this does is overrides all content generated from that content type. What I need to do is move upstream to where the content type is created and override that so that when I go to "add content" I can choose my new custom content type I can input the two variables this content will need and generate a lean, minimal, custom node with only a few divs and those divs organized exactly how I want them.

I've also been reading about preprocess and process hooks but my understanding from what I have read is that these modify the output of the node after it is generated by content type and content and do not let me modify the creation of the content type itself.

Maybe I am going about this all bass ackwards so alternative paths to the same destination would be appreciated.

I hope this explanation is clear. Thanks for any help.

Comments

I'll take a stab at this,

Timon Davis's picture

I'll take a stab at this, though I'm not sure I'm 100% on understanding your goal. It sounds to me like you're trying to create a simpler interface when you go to create a node. Then you want that node's output to be as clean as possible. This is an understanable goal, especially if you're working with clients who value simplicity over power.

First of all, it is worth noting that any content type is going to store a bunch of information. Even if you're not concerned with it where your functionality is concerned, Drupal is attaching all kinds of data to your content types. A lot of Drupal's power actually comes from the ease with which database entities can be tied back to a Node or Content Type.

That being said, my own solution would go something like this (for the record, you'll want to document this somewhere, if you move forward with such a plan):

  1. Clean up the Add Content form with hook_form_alter()
  2. Override targeted output

Clean up the Add Content form with hook_form_alter()

To simplify the node creation form, you have a great tool at your disposal. This tool is called the Form API. All forms in Drupal should conform to a standard of nested arrays, which you can capture, access and modify from the module perspective.

I'll let you look up the details about that in your own good time, but for the time being this is what you need to know about...

hook_form_alter(&$form, $form_state, $form_id) {

  $custom_ct_form_id = $machine_name_of_type . '_node_form';

  switch($form_id) {

    case($custom_ct_form_id):{

       $form['additional_settings']['#access'] = FALSE;
       break;
    }
    default:
    break;
  }
}

You'll have to create a module to execute the above, which is quite worth your time to learn how to do (if you haven't already). You can do something this simple within an hour with the avaialble documentation online.

The box with all the extra junk at the bottom is all part of the additional_settings group. By giving that array an #access property value of FALSE, you prevent that content from being displayed. This is ideal because you still need the default values from those fields in order to create the content type (unless you create a node from scratch via code, but I wouldn't recommend that unless you're ready to dig deep).

Override Targeted Output

Alas, other than using the controls provided on the content type 'manage displays' page, the only way to clean up the output of the node is through templating. If the node view page isn't what you're trying to get at, I'm still not clear on where the output is that you're trying to modify. Could you provide, perhaps, a relative path and a screen capture?

Tip

Try to think of the content type as a unit of data as opposed to a display or a page. Anyplace you see that data is going to be a Display (the most classing being the Node display, which you described overriding). The Display is where you have to affect the output. The content type itself does very little to manage its output -- it really just stores the data and some preferences.

I hope this helps - if I'm missing the point, let me know :)

Simplify module

dougstum's picture

https://drupal.org/project/simplify

will help you clean up the edit form

Clarification

WarrenK's picture

I can see that my original question led readers down the wrong path. Apologies!

  1. I am not trying to change the content type creation form. I have it set up to accept input of two variables, a text field and a link to an image. These two variables show up in the generated content type and when I use Firebug on a page that uses this content type I can find them with no problem.

  2. Restating my original request, where are the templates (if any) that

structure->content types->add content type

uses to generate a new content type? If I could get into the innards of such a template I could possibly override the generated content type. The objective, as I said before, to remove extraneous divs and classes surrounding the two fields referenced in #1, above -- AND -- to add a named div that would encompass the divs that are currently being generated. That is the major stumbling block that I have encountered as I am trying to theme the background and can't find an existing class attached to an encompassing div that I could override, as I do with the individual fields.

Since I posted originally I located my copy of The Definitive Guide to Drupal 7 and am re-reading the chapters on theme hooks and suggestions, as well as process and preprocess hooks, and the render API to see if that is where I should be focusing my attention.

Seattle

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: