Theme "Create Content" page

monkeybeach - August 6, 2007 - 09:22

Is there anyway to override the function that controls the HTML of the create content list:

/**
* Present a node submission form or a set of links to such forms.
*/
function node_add($type = NULL) {
  global $user;

  $types = node_get_types();
  $type = isset($type) ? str_replace('-', '_', $type) : NULL;
  // If a node type has been specified, validate its existence.
  if (isset($types[$type]) && node_access('create', $type)) {
    // Initialize settings:
    $node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type);

    drupal_set_title(t('Submit @name', array('@name' => $types[$type]->name)));
    $output = drupal_get_form($type .'_node_form', $node);
  }
  else {
    // If no (valid) node type has been provided, display a node type overview.
    foreach ($types as $type) {
      if (function_exists($type->module .'_form') && node_access('create', $type->type)) {
        $type_url_str = str_replace('_', '-', $type->type);
        $title = t('Add a new @s.', array('@s' => $type->name));
        $out = '<dt>'. l(drupal_ucfirst($type->name), "node/add/$type_url_str", array('title' => $title)) .'</dt>';
        $out .= '<dd>'. filter_xss_admin($type->description) .'</dd>';
        $item[$type->type] = $out;
      }
    }

    if (isset($item)) {
      uksort($item, 'strnatcasecmp');
      $output = t('Choose the appropriate item from the list:') .'<dl>'. implode('', $item) .'</dl>';
    }
    else {
      $output = t('No content types available.');
    }
  }

  return $output;
}

I've tried the usual phptemplate_node_add way in template.php but it doesn't work. I really don't want to have to create a module to do this - seems like total overkill just to adjust the html. I'm looking at just hacking the core at this point and having done with it just to get off this project and onto something more interesting!

post deleted

christefanø - August 6, 2007 - 17:44

post deleted

post deleted

christefanø - August 6, 2007 - 17:43

post deleted

One thing you can do is

christefanø - August 6, 2007 - 10:13

One thing you can do is alias the node/add and node/add/type paths to a page containing the HTML markup you want. You can include PHP or use something like hidden content if there are several levels of permissions and you want to hide some content types from certain roles.

Sounds promising!

monkeybeach - August 6, 2007 - 10:56

Lol these forums are pretty broken today eh? :-)

What you're recommending is close to what I was considering (see email I sent) and given the create content menu item is unchangeable I'm guessing the alias technique you mention would help sidestep that issue.

How do I create an alias? Is that the HTTP redirect you were talking about in the email you sent?

=-=

VeryMisunderstood - August 6, 2007 - 11:09

aliases are created with the path.module (part of core) when enabled you have a menu item at administer -> url aliases
_____________________________________________________________________________________________
give a person a fish and you feed them for a day but ... teach a person to fish and you feed them for a lifetime

Interesting

monkeybeach - August 6, 2007 - 11:45

Yeah seen most of that, although i did find that a new theme page could override the content creation page, page-node-add.tpl.php worked nicely but i just want to override the content, not the navigation, header etc.

i tried stripping it down to node-add.tpl.php and this didn't work sadly. Maybe I can override it in node.tpl.php with some php though. I'll give that a go.

PHP Page solution

voidengine - November 30, 2007 - 16:14

I ended up following christefano's advice and put this code in a php page. Works great, thanks!

In my case, I'm running an intranet where I create a bunch of nodes used in staff profiles. The staff don't need to create these nodes (just edit them), so I used some conditions to remove them from the list, unless the admin is logged in.

Also, I don't want the users to see an empty 'Create Content' page, so I manually add one last item, which is a link to their profile page.

<?php
global $user;
$types = node_get_types();
foreach (
$types as $type) {
    if (
function_exists($type->module .'_form') && node_access('create', $type->type)) {
       
$type_url_str = str_replace('_', '-', $type->type);
       
$title = t('Add a new @s.', array('@s' => $type->name));
       
$out = '<dt>'. l(drupal_ucfirst($type->name), "node/add/$type_url_str", array('title' => $title)) .'</dt>';
       
$out .= '<dd>'. filter_xss_admin($type->description) .'</dd>';
       
$item[$type->type] = $out;
        if (
$type->type == 'page' ||
           
$type->type == 'story' ||
           
$type->type == 'profile_header' ||   
           
$type->type == 'profile_arrowstreet' ||
           
$type->type == 'profile_personal' ||  
           
$type->type == 'profile_professional' ||
           
$type->type == 'profile_myportfolio1' ||  
           
$type->type == 'profile_myportfolio2' ||
           
$type->type == 'profile_myportfolio3') {
                if ((
$user->uid == 0) || ($user->uid > 1)) {
                    unset(
$item[$type->type]);
                }   
            }
        }
    }
uksort($item, 'strnatcasecmp');
$item['profile'] = '<dt>'. l(drupal_ucfirst('My Profile'), "user/".$user->uid."/edit", array('title' => $title)) .'</dt>';
$item['profile'] .= '<dd>Edit your staff profile pages</dd>';
$output = t('Here are the ways that you can contribute content to the Intranet:') .'<dl>'. implode('', $item) .'</dl>';
print
$output;
?>

Another possible solution...

platypusbill - January 10, 2008 - 16:03

I just wanted to add a container for the generated 'create content', and so in the content section of my main page I added a simple test. Might not be very pretty and there is a limit to what it can achieve, but at least it is simple and readily extendable.

--PB

<div id="main">

<div id="content">
<?php if ((arg(0) == 'node' && arg(1) == 'add')): ?>
<div class="reb">
<?php endif; ?>

<?php print $content; ?>

<?php if ((arg(0) == 'node' && arg(1) == 'add')): ?>
</div>
<?php endif; ?>

</div> <!-- content -->

</div> <!-- main -->

 
 

Drupal is a registered trademark of Dries Buytaert.