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 />

}<br />

'type' => STREAM_WRAPPERS_READ_VISIBLE,<br />

),<br />

);<br />

The array is keyed on our wrapper's scheme, in this case twitpic. Each scheme must<br />

in turn define another associative array with the following keys:<br />

• name: A short descriptive name for our wrapper.<br />

• class: The name of your PHP class that implements <strong>Drupal</strong>'s stream<br />

wrapper interface.<br />

• description: A sentence or two describing what this wrapper does.<br />

• type: A constant indicating what type of stream wrapper this is—readable<br />

and/or writeable, local or remote, among other things. These are defined<br />

in includes/stream_wrappers.inc and can be reviewed at: http://api.<br />

drupal.org/api/drupal/includes--stream_wrappers.inc/7<br />

Note that in our example we have defined our wrapper as STREAM_WRAPPERS_<br />

READ_VISIBLE. This means it is read only, but visible in <strong>Drupal</strong>'s UI. An example<br />

of a wrapper that is not visible in the UI is <strong>Drupal</strong>'s temp:// scheme, which is for<br />

internal use only (it is set to STREAM_WRAPPER_HIDDEN).<br />

This is all that is needed to implement your own custom stream wrapper. It may<br />

seem like a lot, but once you understand what needs to be implemented, it is really<br />

quite simple.<br />

Now that your stream wrapper is finished, you will be able access photos from<br />

Twitpic as easily as any other remote source using <strong>Drupal</strong>'s File API. Now that we<br />

can do this, let's look at some of the ways in which <strong>Drupal</strong>'s Image API can be used<br />

to modify and manage images.<br />

In this example we have mostly focused on the <strong>Drupal</strong>-specific part<br />

of writing stream wrappers. For more general documentation on<br />

stream wrappers see http://us2.php.net/manual/en/intro.<br />

stream.php<br />

[ 325 ]

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

Saved successfully!

Ooh no, something went wrong!