For a site I'm building I'd like to be able to replace the menu items the viewer sees with a custom font. Sognwriter work just fine in content that's submitted in nodes, but doesn't work outside of that.

Is there a way to make signwriter theme any tag (such as menu a's) with a custom font?

Thanks in advance

Comments

wrunt’s picture

Drupal's filters don't apply to menu items. What you want to do has to be done in your theme. To change menu links, you'll have to override theme_menu_item_link. The original code looks like this:

function theme_menu_item_link($item, $link_item) {
  return l($item['title'], $link_item['path'], isset($item['description']) ? array('title' => $item['description']) : array());
}

To override it with signwriter text, you'll want to add something like this to template.php in your theme directory (assuming you're using a phptemplate based theme):

/* I haven't actually tested this code... */
function phptemplate_menu_item_link($item, $link_item) {
  $link = l($item['title'], $link_item['path'], isset($item['description']) ? array('title' => $item['description']) : array());
  if (module_exist('signwriter')) {
    $profile = signwriter_load_profile('Menu Link Profile');
    return signwriter_title_convert($link, $profile);
  }
  else {
    return $link
  }
}

If you use this code, make sure you replace the text 'Menu Link Profile' above with the name of the signwriter profile that you want to use for menu links.

tanc’s picture

Title: Allowing signwriter to theme menus » Allowing signwriter to theme menus - Primary Links

I tried to use the code but it didn't work as expected. I'm not much with PHP so I was unable to work out what was wrong. The closest I've got to signwriting one of the menus (primary links) was to use this code in my page.tpl.php :

    $profile = signwriter_load_profile('myprofile');
    $primlinks = theme('links', $primary_links);
    print signwriter_title_convert($primlinks, $profile);

But unfortunately the $primlinks value is an array which signwriter then complains about. Do you know a way of succesfully doing this?

tanc’s picture

I've found the solution:

<?php
$profile = signwriter_load_profile('primlinks');
if (is_array($primary_links)) : ?> 
<ul id="main-nav">
<?php foreach ($primary_links as $link): ?>
<li><?php print signwriter_title_convert($link, $profile);?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>

Seems to work nicely.

wrunt’s picture

Nice work, that's a good solution.

For anyone else trying to use signwriter with menus, Tanc's solution will work with the 'Primary Links' and 'Secondary Links', but not with menus in general. The solution I gave should work for normal menus, but not for the primary and secondary links, which in drupal 4.7 are part of the menu system, but are treated differently to other menus.

Annika’s picture

Title: Allowing signwriter to theme menus - Primary Links » Getting errors

I tried Tanc code but are getting a lot of red errors:

* warning: mkdir(signwriter-cache): Permission denied in /Library/WebServer/Documents/fixxxa/includes/file.inc on line 91.
* warning: imagegif(): Unable to open 'signwriter-cache/c109cb1a75518ea243f9e7ee2420de81.gif' for writing in /Library/WebServer/Documents/fixxxa/modules/signwriter/signwriter.module on line 576.
* warning: mkdir(signwriter-cache): Permission denied in /Library/WebServer/Documents/fixxxa/includes/file.inc on line 91.
* warning: imagegif(): Unable to open 'signwriter-cache/15515a2d4837e5bb151941ac4c2ded7c.gif' for writing in /Library/WebServer/Documents/fixxxa/modules/signwriter/signwriter.module on line 576.
* warning: mkdir(signwriter-cache): Permission denied in /Library/WebServer/Documents/fixxxa/includes/file.inc on line 91.
* warning: imagegif(): Unable to open 'signwriter-cache/8f9ede2e6126e35ef9db7e214474e901.gif' for writing in /Library/WebServer/Documents/fixxxa/modules/signwriter/signwriter.module on line 576.
* warning: mkdir(signwriter-cache): Permission denied in /Library/WebServer/Documents/fixxxa/includes/file.inc on line 91.
* warning: imagegif(): Unable to open 'signwriter-cache/37a91ce21941d7cac659037dc3c0a26f.gif' for writing in /Library/WebServer/Documents/fixxxa/modules/signwriter/signwriter.module on line 576.

I've enabled the module, created a Signwriter profile, exchanged the primary navigation code in page.tpl.php for Tanc's snippet, modified it to correspond with my Signwriter profile and CSS, set read/write permissions on the Font folder and the Signwriter folder.

What am I missing?

I'm running Drupal 4.7.2 on Mac OSX.

Cheers,

Ayza

wrunt’s picture

it looks like your web server doesn't have permissions to create files in your drupal directory (/Library/WebServer/Documents/fixxxa/). Try creating the directory /Library/WebServer/Documents/fixxxa/signwriter-cache and then 'chmod 777 /Library/WebServer/Documents/fixxxa/signwriter-cache', just to be certain the web server can write to it.

Alternatively, you can make your drupal directory writable to your web server. If your server is apache and it uses the apache user, then try 'chown -R apache /Library/WebServer/Documents/fixxxa/'. If the permissions are ok on the folder then the web server should be able to write to it.

wrunt’s picture

Status: Active » Closed (won't fix)