Thanks this is a great module. Was struggling to style internal links as buttons using your great module. I realised the span tags needed adding but wanted to use the drupal l function so that links were not hard coded. Eventually I got there with the following:

print l('<span>' .t('Sign Up') .'</span>', 'user/register', array('attributes' => array('title' => t('Create a new user account.'), 'class' => 'button'), 'html' => 'TRUE'));

You might wish to add this to the documentation to speed things up for newbies like myself e.g.

The button style can also be applied to hyperlinks by adding the .button class and a span tag. The span tag allows the sliding doors technique to be applied:
My Button Link

Applying the button style to links using the drupal l function:
print l('<span>' .t('Sign Up') .'</span>', 'user/register', array('attributes' => array('title' => t('Create a new user account.'), 'class' => 'button'), 'html' => 'TRUE'));

Thanks again for a great module, really helped me out.

Comments

skilip’s picture

The code below allows you to choose a button style formatter for the link module.

/**
 * Impelmentation of hook_field_formatter_info().
 */
function YOUR_MODULE_field_formatter_info() {
  return array(
    'button_link' => array(
      'label' => t('Themed button'),
      'field types' => array('link'),
      'multiple values' => CONTENT_HANDLE_MODULE,
    ),
  );
}

/**
 * Implementation of hook_theme()
 */
function YOUR_MODULE_theme() {
  return array(
    'YOUR_MODULE_formatter_button_link' => array(
      'arguments' => array('element' => NULL),
    ),
  );
}

/**
 * Theme function for styled links.
 */
function theme_YOUR_MODULE_formatter_button_link($element) {
  $output = '';
  foreach (element_children($element) as $key) {
    $item = $element[$key]['#item'];
    $item['attributes']['class'] = ($item['attributes']['class'] ? $item['attributes']['class'] .' button' : 'button');
    $item['html'] = TRUE;
    $output .= $item['url'] ? l('<span>'. $item['display_title'] .'</span>', $item['url'], $item) : '';
  }
  return $output;
}
asb’s picture

@skilip: Do I understand this correct: Your snippet is a skeleton for an add-on module and doesn't go into the theme's template.php file, but in something like YOUR_MODULE.module (and thusly requires an .info file and the like)?

Excuse the stupid non-coder question ;)

pmathur01’s picture

Is it possible to theme links in views to button? Example I have link to [node_link] for view more which will result in a link . Is it possible to make this into a button with this module?
Thanks
Prerna

MBroberg’s picture

Yes, you have to rewrite the field and include span tags around what you want the button to say. Then write "button" in the class.