Themers

Adding different fields

Last modified: November 10, 2009 - 12:59

The way to add any FAPI field is to use the drupal_alter hook. All you need is a custom module with this function and an info file. Remember to replace the MYMODULE with a relevant module name.

; MYMODULE.info
name = MYMODULE
description = "Adds a select element to all imagefield_extended widgets"
package = CCK
core = 6.x
dependencies[] = imagefield_extended

<?php
/**
* @file
* MYMODULE.module
* Adds fields for imagefield_extended widgets.
*/

/**
* Callback for drupal_alter('imagefield_extended_widget').
*/
function MYMODULE_imagefield_extended_widget_alter($element, $extra_values) {
 
// If you need the field or widget to conditionally add a FAPI field, use these.
 
$field = content_fields($element['#field_name'], $element['#type_name']);
 
$widget = $field['widget'];

  return array(
   
'MYFIELD' => array(
     
'#type' => 'select',
     
'#title' => t('My select field'),
     
'#options' => array(
        
'a' => t('A option'),
        
'b' => t('B option'),
      ),
     
// this makes b the default value when the value is not set.
     
'#default_value' => isset($extra_values['MYFIELD']) ? $extra_values['MYFIELD'] : 'b',
    ),
  )
}

?>

The data should be saved and loaded by FileField and your theming functions would present the value to the end user.

OpenLayers Tutorial

Setting up a Map

  1. Download and enable the OpenLayers module and the ctools module
  2. You'll also want to download the Views module if you want to display any Drupal data on a map.
  3. Enable OpenLayers, OpenLayers UI, and OpenLayers Views (in addition to Views and the other required modules).
  4. Create a view (e.g. page) and set "OpenLayers" as the Style setting (if you just want to see something skip to step 8).
  5. Go to the OpenLayers administration page (admin/settings/openlayers) and the layers tab. Add a new layer if desired.
  6. Go to the OpenLayers administration page (admin/settings/openlayers) and the presets tab. Create a new preset with a map layer and the view you created before will be an option as an overlay layer.
  7. Save your new map preset and go back to the views interface.
  8. Using the gear/settings option under Style: 'OpenLayers' and edit the options to your liking.
  9. Save your view.
  10. View the view and its generated map.

Example of Theming a pinboard with custom node-type and module Views

Last modified: November 8, 2009 - 19:11

This describes the steps to theme some Views output. I had to figure this out for a client who wanted his user-community to share "notes". The overall look of this part should be as pinboard with sticky notes on it.

Functional Part

I prefer to use Drupal modules CCK and Views for building custom node types and selecting desired data. So, the first step is to assure that modules Views and CCK are installed and set up. You can optinally install further Drupal modules like Date, Link to build your "note".

Then create a custom node type named "note". A "note" is the information-unit with a Title, a Textfield and some more fields of your choice (for example, a date-field could be useful). Just follow the Installation-Readmes for Drupal modules and CCK-modules to get more information bits into your note.

The pinboard is the "container-element" for many "notes". This can be done by module Views easily. Just add a new View named "pinboard" that shows content of type "node". Now create a View-Page named "pinboard page" and set it to show a grid of fields. Select any Fields that should show up on your note and arrange the order of the fields on the note. Limit the Title-Field and the bodytext to 35 / 65 characters so it would fit onto a small note-graphics.

Views Index (A-Z Grouping)

Last modified: November 3, 2009 - 06:44

There have been many support requests and forum topics about creating an index page with views although there seems to be little information on how to achieve it.
It is relatively simple when you know how, and using using grid formatting and grouping we'll build an index page that will look sort of like this:

A
Node Title | Node Title | Node Title

B
Node Title | Node Title | Node Title
...

The view export below will display all nodes in the above fashion. Once you have imported this view create a new php file in your current theme folder:
views-view-field--index--title.tpl.php (don't forget to clear cache)

<?php
print strtoupper($output[0]);
?>


$view = new view;
$view->name = 'index';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'title' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,

OpenLayers Module Architecture

Last modified: November 11, 2009 - 17:49

Presets

OpenLayers presets contain

  • Map Settings
    • Height, width
    • Centerpoint
    • OpenLayers source file, theme location, ProxyHost
  • Enabled Behaviors
  • Enabled Layers
  • Enabled Styles

OpenLayers Map Views

OpenLayers map views use the Views module merely as a way to put a map on a page. They do not, like other views, query data by themselves. To add Drupal nodes or data to a OpenLayers map view, enable openlayers_views and create a OpenLayers Map Data view, and add it as a layer.

OpenLayers Map Views pull from OpenLayers Presets

Layer Types

Layer types are plugins. A base set of layer types is provided within the OpenLayers module, more are provided within the openlayers_layers module, and other contrib modules like MapBox can provide even more.

Layer Types generate Layers and provide their functionality

Layers

Layers are exportables which contain per-layer configuration.

Styles

Styles are exportables which contain OpenLayers Styles. They are attached to layers by the configuration in Presets.

Bluga WebThumbs

Last modified: November 19, 2009 - 19:31

The Bluga WebThumbs module provides a very complete implementation of the Bluga WebThumb API. It does not, however, provide much else. The most useful (and intended) use of this module is either to be used by other modules wishing to build on it or provide a way for a Drupal site with a custom theme to display a thumbnail based on the content of a node. This can be used with a custom PHP filter if you prefer as well.

Configuration

  • Here you will need to enter your API key. The link to sign up for an account is on that page.
  • You will also select a directory under which to store your thumbnails. The configuration screen will warn you if the directory needs to be created or made accessible for writing.

    Creating a Thubmnail

    The basic syntax is:

    <?php
    print bluga_webthumb('http://drupal.org');
    ?>

  • Syndicate content
     
     

    Drupal is a registered trademark of Dries Buytaert.