I'm stumped.

I've been using the code at http://drupal.org/node/219664 to create a Publish menu in a block. It worked perfectly for weeks while I was developing.

This afternoon I made a couple of changes before going live : Enable cache, Disabled Theme auto-rebuild etc... All of sudden the code stopped listing all my custom content types, and only shows a link to publish polls. It's apparently related to the "Rebuild theme registry on every page" option.

It's not a content access issue because if I remove "&& node_access('create', $type->type)" then nothing changes. However, if I remove "if function_exists($type->module .'_form')" (and keep the node_access condition) then everything looks like it did before.

The weirdest part is that this also happens to my Webmaster role which has *every* permission enabled. ALSO, when I go the Module pages the code functions properly. On any other page it doesn't.

Reenabling "Rebuild theme registry on every page" makes the (full) code work again but I cannot go live with that option on!

Thoughts? Quickly (please)?

Comments

dddave’s picture

But the code you are using is marked as D5 code and you tagged this issue as D6.
So maybe the code you use needs some tweaking to go along nicely with D6?

talino’s picture

I didn't even notice the tag on the code, simply copied and adapted it... My mistake. Although I still need to understand (urgently) why D6 doesn't like the code and if removing the condition that checks for the existence of the form function is a bad idea (it makes the block work and is what I'd do if I don't have another solution, I'm on a tight deadline).

Alternatively, a cleaner D6 procedure for printing the Create Content links in a block would be much appreciated.

Thanks a lot.

tnanek’s picture

What I would do is create a menu and manually add links to the create content pages for each content type you want to be in this menu - when Drupal displays the given menu block, it will automatically hide those that are not accessible to the user.

You can also only display the block for this to certain roles easily enough on the block configuration page.

--EDIT--

This also explains why that code hasn't been updated. I recall hearing somewhere prior that the menu now checks access permissions itself as a feature of version 6, thus the code referenced above isn't required anymore.

talino’s picture

I didn't know D6 checked permissions first for explicit paths in menus. Fortunately I only have around 10 content types. Your idea seems to be the simplest solution. I've deactivated the theme registry auto-rebuild and everything's OK. Thanks!

However, your solution had created a new issue for me (as most solutions do...) : in my earlier implementation I added some CSS class definitions to a couple of menu items (one of them is a link to a help page, not a create page, so I needed a little question mark PNG next to it). However, now I can't do that directly. I understand that I need to go through theme_menu_item_link but I haven't a clue on how to automatically inject class name into the links based on some criteria (say, the last URL argument, e.g. class="article" for "/node/add/article").

-- EDIT --

After quite a bit of newbish struggling, I came up with the following in my template.php file. It works, but I'm not sure it's the most elegant way to handle this. It will stop working if I change a link and I'll never find out where the code was coming from :)

<?php
function mytheme_menu_item_link($link) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }
  if ($link['menu_name'] == 'menu-publier') {
    switch ($link['href']) {
      case 'node/add/probleme-technique':
        $link['localized_options']['attributes']['class'] = 'probleme';
        break;
      case 'node/83':
        $link['localized_options']['attributes']['class'] = 'aide';
        break;
    }
  }
  return l($link['title'], $link['href'], $link['localized_options']);
}
?>

Even if you can't help me out on this one, thanks a lot for your suggestion above.

talino’s picture

It's not a real solution since what I need to add classes to are the list elements inside the menu, not the anchor tags. CSSing anchor tags doesn't let me handle margins and padding the way I need to. The site will hold, at least, when launched. That's the most important thing, so thanks again. But I'd like to find a nice solution to this issue. The Menu Class module is total overkill for what I need to do.