Themers

OpenLayers Styles API

Last modified: November 2, 2009 - 02:10

OpenLayers styles definitions are a light wrapper around the functionality provided by styles in the OpenLayers javascript library. A simple style definition (one of the defaults included by the module) is

  $style = new stdClass();
  $style->api_version = 1;
  $style->name = 'default';
  $style->title = t('Default style');
  $style->description = t('Basic default style.');
  $style->data = array(
    'pointRadius' => 5,
    'fillColor' => '#FFCC66',
    'strokeColor' => '#FF9933',
    'strokeWidth' => 4,
    'fillOpacity' => 0.5
  );
  $styles[$style->name] = $style;

The contents of $style->data are passed directly to the OpenLayers javascript, and therefore have documentation on OpenLayers.org.

To provide custom styles in a module or feature, implement hook_openlayers_styles_info, and return an array of styles, keyed by style name.

How to apply a patch to a module - beginner's version

Last modified: November 1, 2009 - 17:11

Much of the existing documentation (see links below) on how to apply a patch is extremely cryptic and assumes more technical knowledge than some aspiring, but worthy patchers have.

But even those with somewhat lesser technical know-how may want (or need) to apply a module patch from time to time. For instance, if there is an important feature that has been developed for your module, but that is still not available in an official release. Or if you have reported a bug in the module, and the module maintainer has asked you to test a patch that fixes it.

This how-to provides a very simple step-by-step guide to applying patches to contributed modules. It is designed for first-time patchers and/or less technical folks who have the need to apply a patch from time to time. The how-to specifically relates to applying patches on Windows machines, but the basic information and steps may be helpful for others. It is also written for a localhost configuration, but the same steps would apply to a hosted environment as well, if it is a Windows environment. You'll just need to switch the location where some of the steps are executed.

How to display selected block only for a logged in or not logged in users

Last modified: October 29, 2009 - 22:54

If you have a block that you want to set visible only for logged in users, follow these easy steps:

1. Go to Administration -> Build -> Blocks page;
2. Select "Configure" link next to the name of the block that you want to set visible only for logged in users;
3. After the page reloads scroll down to the "Page specific visibility settings" field, select "Show if the following PHP code returns TRUE (PHP-mode, experts only)" option and paste the following code in the field "Pages" showed below the selection options:

<?php
 
global $user;
  return (bool)
$user->uid;
?>

To display the block only for anonymous users use the following code:

<?php
 
global $user;
  return !(bool)
$user->uid;
?>

Please note: to use this method the PHP filter module must be enabled!

Views Arguments basics

First I want to state that this might be incomplete or very simplifying in some ways, but after more than three years with drupal I still haven't completely grasped this.
This page will try to explain in a very simple way how arguments in views 2 work.

First of all what are view arguments?
Arguments are a way to send information to a view, these arguments can filter the view or modify them. I use them mostly to create dynamic view filters, filters that change according to the content that's on the page, usually with block views or views inside quicktabs.

Example:
I have nodes with a certain term, let's say "cars". I'd like to display a block view on each page with other nodes with the term "cars". Kind of a related articles block.

So, I'll add an argument : Taxonomy: Term ID.
Now since most of pages I'll be looking at will look like this:
www.mysite.com/node/##
I want to take that ## (node id or nid) find out what term is assigned to it (in a specific vocabulary) and then filter my view results according to that nid.

Lets understand the two different types of arguments that are available:
$args and arg() - yes there's a difference.

$args – are arguments that are being passed to the view, so if you have a page view and it has this url
www.mysite.com/pageview

then the arguments are what comes after the page view
www.mysite.com/pageview/first/2/third

Node displays: plugins and how to build your own ones (6--1 series)

Last modified: November 27, 2009 - 13:34

Note: this is only applicable for the 6--1 series of ND

Node displays comes with two plugins: the Empty region render and CSS overrider which you can turn on if you need them. Go to admin/content/types/nd/plugins to enable them if you want to use them. If enabled, a 'plugins' tab will be available on the fields display screen.

It's really easy to write your own plugin, although there might be some problems to alter anything you want. We are still working on a fully flexible system. Please bare with us or send in your patches :)

hook_nd_plugins

Return an array with with plugins you want to be available in the system.

<?php
function hook_nd_plugins() {
 
$path = drupal_get_path('module', 'nd');
  return array(
   
'emptyregionrender' => array(
     
'title' => t('Empty region'),
     
'description' => t('Renders a region when there is no content in it.'),
     
'file' => 'emptyregionrender.inc',
     
'path' => $path .'/plugins',
    ),
}
?>

Now you need to create a file called emptyregionrender.inc and implement 3 other hooks named nd_pluginname_form(), nd_pluginname_submit() and nd_pluginname_process(). Look into the plugin files that come with nd core for inspiration.

Customize pager to use number of results e.g. 1-10, 11-20, etc instead of page number (drupal 6)

Last modified: October 14, 2009 - 17:15

Instead of using the usual page numbers for the pager (1, 2, 3, etc), I wanted to show the number of results i.e. 1-10, 11-20, 21-30, etc. After quite a bit of searching I finally figured out where to do the customizations and how to do it. By theming theme_pager() in includes/pager.inc I managed to get it to work. Maybe someone else will find this useful.

Just remember to change "themename" (in the function name) to the name of your theme, otherwise the override won't work.

<?php
/**
*Override themename_pager()
* Creates a numbered list e.g. 1-10 11-20... instead of the usual page number list i.e. 1 2 3 ...
*/
function themename_pager($tags = array(), $limit = 10, $element = 0, $parameters = array()) {

global $pager_page_array, $pager_total, $pager_total_items;
$page_prev = $pager_page_array[$element] - 1;
$page_curr = $pager_page_array[$element] + 1;
$page_next = $pager_page_array[$element] + 1;
$page_last = $pager_total[$element] - 1;

//Custom Label
$this_pg = $pager_page_array[$element]+1;
$last_pg = $pager_total[$element];
$total = $pager_total_items[0];
$start = $page_curr*10 - 9;
if($this_pg < $last_pg)
$end = $this_pg*10 ;
else
$end = $total;

$label = "Comments $start-$end of $total";
//end of custom label

if ($pager_total[$element] > 1) {

Syndicate content
 
 

Drupal is a registered trademark of Dries Buytaert.