Hi

I´m trying to write a module with a custom link funktion but i dont know how to make it in 5.1
I tryed this way.


/**
* Implementation of hook_link()
*/

function myfile_link($type, $node = NULL, $teaser = FALSE) {
    $links = array();

  if ($type == 'node' && isset($node->myfile) && $teaser == TRUE) {
    $links[] =  theme('myfile_links', $node);     
    }
  return $links;
}

function theme_myfile_links($node) {

    $link = '<img src="/' . drupal_get_path('module', 'mymodule') . '/lock.png" alt="[P]" />';
   
  return $link;
}

But the theme.inc can not use the array. My aim is i want to have a special image in all links from my module....

Dirk

Comments

Michael M’s picture

Use the Drupal API site to find info on hooks, functions, etc.: http://api.drupal.org/api/5/function/hook_link

/**
* Implementation of hook_link()
*/

function myfile_link($type, $node = NULL, $teaser = FALSE) {
	$links = array();
	
	if ($type == 'node' && isset($node->myfile) && $teaser == TRUE) {
		$links['myfile_link'] =  theme('myfile_links', $node);    
	}
	return $links;
}

function theme_myfile_links($node) {
	return array(
		'title' => '<img src="/' . drupal_get_path('module', 'mymodule') . '/lock.png" alt="[P]" />',
		'html' => true);
}

----
http://eUploads.com

designwork’s picture

Hi Michael M.,

unfourtanatly it does not work but i dont know why....

I tryed some of the exampels but nothing worked out.

Any more idea?

mgifford’s picture

I'd say that the easiest place to start with this is to verify if both of these functions are being called or not.

Simply echoing text from within the function will let you know if they are working on some level or not. They you can figure out why the png isn't popping up after you know that the functions are otherwise working as they should.

Mike
--
OpenConcept | WLP | ox.ca
OO | Jean Crowder, MP

designwork’s picture

Hi Mike,

thanks for the help. the funktion is working now. problem was the if statement.

old: if ($type == 'node' && isset($node->myfile) && $teaser == TRUE)

But every node is allways myfile, just with yes or no

new: if ($type == 'node' && $node->myfile && $teaser == TRUE)

This was the hole problem....

Dirk

corel’s picture

To fix your aim, just try hook_link_alter. Code like below:

function theme_myfile_link_alter(&$links, $node) {
  foreach ($links AS $module => $link) {
    $links[$module] ='<img src="/' . drupal_get_path('module', 'mymodule') . '/lock.png" alt="[P]" />'.$link;
  }
}

Or, the most fast way is modify the css file, just add lines like below:
ul.links li {
background-image:lock.png;/** you must specify your png file path to work properly */
padding-left:10px; /** you must specify the width to you image width */
}
Good luck. And if this help you , please tell me, Thanks.