Content Type Template

This is a generic content type module.

All pieces of the module are here together and will need to be split after doing the initial customization.

  1. To start that you should create a new folder in the appropriate "sites/xxx/modules" directory.
  2. Copy the content_type_template.txt file into that folder; then work on the copy, which will become your module.
  3. Using a text editor (e.g. Wordpad), you need to "replace all" the following:
    • replace $content_name$ with the human version of the content type.
    • (it may contain spaces and capital letters)

    • replace $content_type$ with the internal name (no spaces or capitals)
    • for example, the content_name may be "Site Notes" and content_type "sitenotes"

    • replace $content_modifier$ with an extension (primarily for permissions)
    • For example, for a newsletter type, you might use " article". If you don't want this, then replace it with nulls (""). Make sure if you do use this to include a leading space.

  4. Now split this template into the components that are identified with "start" and "end" comments.
  5. Once that's done, you may discard the copied template (keep the original just in case).

  6. Go to another module and copy LICENSE.TXT if you want to distribute the module you create. (Optional if it's only for personal use.)
  7. Check your customizations that might be needed. Then enable the module.

This is now a pretty good starting point for you to do further customization. For some people this may be enough as it is. Either way, enjoy it.

 


README.htm

This will be customized in the above steps.

$content_name$ Module

The $content_name$ module allows the administrator to create a new content type (“$content_type$”).

The “$content_type$” type, as initially configured, is pretty much a clone of the “story” content type. There are three main reasons for using a custom content:

  1. So that taxonomies do not get confused with other content types.
  2. To allow for special rendering through CSS or theme templates.
  3. Database queries can be limited to this type.

While the module may be used without taxonomy (categories), it is really designed to be used with them. Multiple vocabularies (categories) are supported. For example, for a newsletter, one may define an “Issue Date” category and a “Keyword” category and both can be used to access the content. The Category module is not supported and no testing has been done with it.

After creating this module from the template, you are not only welcome to change it, but encouraged to do so. The real purpose of this template is to produce a working (and decently featured) starting point. Additional customization is available to do even more special things for your users.

Installation

This module installs a bit differently than the standard manner simply because of how it is created; follow the template instructions.

Following installation, you should go to the Content Type Settings page and set the default workflow options. I recommend turning all of those options off (including “published”).

Next, define the taxonomy vocabulary (-ies) that you want to use.

Start creating content.

See how it looks and adjust your CSS if you need to.

Installation Note

There is a bug in the core Node module. Check the issue status. It is a simple change and must be applied in order for this module (and others) to work correctly.

Administration

There are two administrative functions:

  • Configure permissions” allows you to determine which user roles can do what with the “$content_type$” content. The access permissions are defined as:
    • Access $content_name$ -- alows the content to be viewed.
    • Create $content_name$$content_modifier$ -- allows a user to create this type.
    • Edit $content_name$$content_modifier$ -- allows a user to edit the type, whether it is theirs or not.
    • Edit own $content_name$$content_modifier$ -- allows a user to edit only his/her own content.
    • Change weight of $content_name$$content_modifier$ -- allows a user to change the weight of a posting so that it moves up or down the list independently from the creation date.
    • Administer $content_name$ -- allows the user to control the administrator settings.
  • $content_name$ Settings” allows you to control how the content appears.
    • Use content teaser  --  specifies whether the normal display will use a teaser format.
    • Number of columns in the index  --  This sets the number of columns that can be displayed in the index page.
    • “>> read more” link text  --  This allows the user to change the text displayed for the links to the full text when teasers are used.
    • "More from" author link text  --  This allows the user to change the text displayed for the links to more contributions from the same author.
    • $content_type$_description  --  Your $content_name$ description. This will be placed at the top of the page, above the selected content and can serve as an introductory text.
    • Categorize list  --  This allows the user to display the content according to the categories configured on the add/edit $content_type$ page. The Taxonomy module must be enabled. The following options require this to be enabled.
    • Display category name for index  --  This allows the user to toggle the visibility of the category name above each index group.
    • Display term list for node display  --  This allows the user to toggle the visibility of the term list above each node (the "submitted by" line).
    • Display term description for index  --  This allows the user to toggle the visibility of the term description in the index.
    • Display category name for content  --  This allows the user to toggle the visibility of the category name above each selected node.
    • Display unused category term  --  This allows the user to specify if the terms index should include terms that are not used (count = 0).
    • Display author names in index  --  This allows the user to toggle the visibility of the author name list on the index page. Requires "Categorize list" to be selected, otherwise it will be defaulted on.

Module Invocation

/$content_type$

If the module is entered with no arguments, then an index is displayed. This contains a list of all taxonomy vocabularies (categories) that are assigned to the "$content_type$" content type (if using categories) and a list of all $content_type$ authors.

/$content_type$/keyword/nnn

When the module is entered with a single argument, it is the ID of terms to be used to select a list of nodes to display. This is the same format as can be used with “taxonomy/term.”

/$content_type$/author

If no argument is used with the “author” specification, then a list of the titles of the most recent submissions for each author is displayed.

/$content_type$/author/nnn

When entered with an author's user ID or name, all submissions from that author are displayed.

Blocks

Four blocks are defined in this module:

  1. “$content_name$ Categories” -- id="$content_type$-block-0"
  2. This block displays the taxonomy terms that are in defined as links.

  3. “Recent Pink Slips.” -- id="$content_type$-block-1"
  4. The configuration includes a setting for how many post titles to show in the block.

  5. “$content_name$ Authors” -- id="$content_type$-block-2"
  6. This block shows the list of all $content_name$ authors and a count of how many submissions they have made.

  7. “Unpublished $content_name$$content_modifier$s” -- id="$content_type$-block-3"
  8. This block shows the list of all $content_name$$content_modifier$s that are waiting to be published.

Block Visibility Recommendations

The “Page specific visibility settings” for the first three blocks should be set to “Show if the following PHP code returns TRUE” and include this code:

<?php
   
if (arg(0) == '$content_type$') { return TRUE; }
    if (
arg(0) == 'node') {
     
$nid = arg(1);
     
$node = node_load(array('nid' => $nid));
      return (
$node->type == '$content_type$');
    }
/* end node */
?>

For the “Unpublished $content_name$$content_modifier$s” I recommend setting it to show only for the roles that have the authority to approve the post, and limit it to the “Admin” page and all “$content_type$” pages (“$content_type$/*”).

Additional Blocks

Another block that might work well with the $content_name$; is the “Author Information” block that is provided with the Profile core module.

Set the visibility to something like this:

<?php
 
global $user;
 
$match = FALSE;
 
$types = array('$content_type$' => 1, 'faq' => 1, 'recipe' => 1); /* <-- change the types here */
 
$p0 = arg(0);
 
$p1 = arg(1);
 
$p2 = arg(2);

  if (
$p0 == 'node' && is_numeric($p1)) {
   
$nid = $p1;
   
$node = node_load(array('nid' => $nid));
   
$type = $node->type;
    if (isset(
$types[$type])) { $match = TRUE; }
    if (
$node->uid == 1) { $match = FALSE; }
  }

  if (
$p0 == '$content_type$' && $p1 == 'author' && $p2 != '') {$match = TRUE;}

  return
$match;
?>

$content_type$.install

This module has an “install” component that also includes an “uninstall” function. The initially set install function only logs a message that the module has been installed. The uninstall function does more:

  1. Removes all nodes with the “$content_type$” type. (Make sure you really want to do this.)
  2. Deletes the “$content_type$” content type.
  3. Deletes all system variables associated with this module.
  4. Clears the cache so that no remnants are displayed by accident.
  5. Logs a message indicating that it has been removed.

Following removal of the module, you may want to clean up any taxonomies that you had created for this content type.

Special Functions

There are some special functions that can be used on a custom page. These can be used in a handy-dandy overview index page.

  1. $content_type$_term_index -- creates a list of all the taxonomy terms associated with a vocabulary.
  2. $content_type$_author_index -- creates a list of all users who have created a $content_type$ node.
  3. $content_type$_author_count -- returns a count of how many $content_type$ nodes the author has created.

The first two functions will accept a parameter to specify the list type, which can be “list,” “table,” or “stream.” The list format produces an unordered (bulleted) list; the table type produces a table (with a heading); and the stream format separates the items by a bar (“|”).

The third function requires a parameter to specify which author to count. It may be either the user's id (numeric) or user's name.

The term_index function requires a numeric parameter to specify which vocabulary to traverse.

Examples:

  • print $content_type$_term_index(8, "table");
  • print $content_type$_author_index("list");
  • print "Nancy has written " . $content_type$_author_count(47) . "$content_modifier$s.";

Additional Information

The weight feature is implemented in pretty much the same way the Weight module does -- that is it highjacks the “sticky” attribute. “Sticky” still works but it may look funny if you browse the actual database contents.

All the queries, except the Unpublished and Recent blocks, sort by weight (and “sticky”) in ascending order, then creation date in descending order, so the most recent posts are first. If this meets your needs, which it should for most people, then there is no need to worry. If not, you will have to locate all the queries and fix them. Generally, I would rather twiddle with the creation date in the “Authoring information” to make this work my way.

The Recent $content_name$ block does not use the weight/sticky field in its sort; it is purely by creation date.

The Unpublished block sorts by creation date in ascending order so that the posts that have been waiting the longest are on top.

 

-- This module was created from the Generic Content template (version 1.0) by Nancy Wichmann.

Comments

Where is the download?

Hi Nancy,

Interesting stuff! But where is the download or dis I miss something?

Cheers, Joep

No, you didn't miss it

This is not a contributed module yet, so you have to email me for it.