You are here

How do I change a hyperlink to an image button in a Drupal module?

1 post / 0 new
xarzu
Offline
Last seen: 2 years 10 months ago
Joined: 2015-12-08 23:40
How do I change a hyperlink to an image button in a Drupal module?

I want to make a button on location on a php file that currently is just a hyperlink.
Currently, the code segment appear in a browser with the text "Donate now", but I want it to be a paypal button instead.

All this is part of a paypal module I have set up in Drupal. I have already figured out the proper way to use a .css file with this module to modify another aspect of it. And now I want to change the textual hyperlink to a paypal button.

The line of code in question looks like this in the paypal_donations_single.tpl.php file:

<?php echo t($variables['submit_value']); ??>

The hyperlink text appears in the browser as "Donate now". This text appears in the .inc file includes\paypal_donations.admin.inc:

$form[$type_key]['paypal_donations_' . $type_key . '_submit_value'] = array(
'#title' => t('Form submit text'),
'#type' => 'textfield',
'#description' => t('The button text when someone sends the form'),
'#default_value' => variable_get('paypal_donations_' . $type_key . '_submit_value', 'Donate now'),
);

This line of code is of particular interest to me:
'#type' => 'textfield',

Maybe there is an example somewhere that has a graphic as a '#type'.

I have an extensive list of modules already and when I did a grep-style dos/cmd file findstr command I found many examples. The one that looks the most promising is:
'#type' => 'image_button'

and the accompanying code looks like this:
$form['go'] = array(
'#type' => 'image_button',
'#src' => $options['image'],
'#submit' => array('ctools_jump_menu_submit'),
'#attributes' => array(
'class' => array('ctools-jump-menu-button'),
)

based on what I can observe, I assume that all I need to do is change this:

$form[$type_key]['paypal_donations_' . $type_key . '_submit_value'] = array(
'#title' => t('Form submit text'),
'#type' => 'textfield',
'#description' => t('The button text when someone sends the form'),
'#default_value' => variable_get('paypal_donations_' . $type_key . '_submit_value', 'Donate now'),
);

into this:

$form[$type_key]['paypal_donations_' . $type_key . '_submit_value'] = array(
'#title' => t('Form submit text'),
'#type' => 'image_button',
'#src' => $options['image'],
'#description' => t('The button text when someone sends the form'),
'#default_value' => variable_get('paypal_donations_' . $type_key . '_submit_value', 'Donate now'),
);

I only need to figure out how to best assign this '#src" variable. When I looked into the $options settings, the complexity and flexability reached new heights and I think now is a good time to ask for some help online with more experienced Drupal scripters and developers. Perhaps there is an easier way to assign this value a hardcoded path and image name.

Pease help