18.10.2016 Views

Drupal 7 Module Development

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 11<br />

• form callback: If your effect allows users to enter configuration data<br />

(such as the width and height fields in the previous scale example), then this<br />

indicates the function that defines your configuration form. This value is<br />

optional. If your effect does not require any configuration information,<br />

then this key is not necessary.<br />

• summary theme: After your effect is added to a style, you can create a theme<br />

callback which returns customized text to be displayed on the styles admin<br />

screen. For instance, the rotate effect displays the number of degrees that the<br />

user entered. This value is also optional. If you don't provide it, your effect<br />

will display the value you provided in the label key.<br />

As you can see, we have defined three callbacks that we need to create. First, we will<br />

look at our configuration form. It would be nice for users to be able to specify what<br />

text they would like on watermarked images, so we will offer the option to enter<br />

custom text as well as give them an option to indicate what color it should be.<br />

/**<br />

* Form structure for the watermark configuration form.<br />

*<br />

* @param $data<br />

* The current configuration for this watermark effect.<br />

*/<br />

function watermark_form($data) {<br />

$form['text_color'] = array(<br />

'#type' => 'textfield',<br />

'#default_value' => (isset($data['text_color'])) ? $data['text_<br />

color'] : '#FFFFFF',<br />

'#title' => t('Text color'),<br />

'#description' => t('The color of the text to be used for this<br />

watermark. Use web-style hex colors (#FFFFFF for white, #000000 for<br />

black).'),<br />

'#size' => 7,<br />

'#maxlength' => 7,<br />

'#element_validate' => array('image_effect_color_validate'),<br />

);<br />

$form['text'] = array(<br />

'#type' => 'textfield',<br />

'#default_value' => (isset($data['text'])) ? $data['text'] :<br />

'<strong>Drupal</strong> loves kittens!',<br />

'#title' => t('Watermark text'),<br />

'#description' => t('Text to be written on the image.'),<br />

'#size' => 30,<br />

'#maxlength' => 60,<br />

[ 335 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!