absolute urls

July 1st, 2008

use the url() function like this: url($some_path, array('absolute' => TRUE));

note on the global $user object

April 10th, 2008

interesting fact: hook_user() hooks aren’t run when the global $user object is loaded. This means that if your module is storing custom data in the user object, it either needs to user_load() the global user itself, or it needs to store its data as part of the user object’s ‘data’ field.

uid of current user on profile pages

January 3rd, 2008

the user var on profile pages refers to the user whose profile it is. how to get access to the current [non-profile] user. via.

menu item title translation

December 30th, 2007

menu item title localization - in Drupal 6, menu item titles should be *untranslated*, and you can provide either a translation callback or arguments for the regular translation function [t()]. this is different from Drupal 5, where menu item titles should be translated (usu. the t() function would just be put around the title in the menu item def’n).

dueling image toolkits

July 22nd, 2007

so, Image Enhanced Scaling (adds sharpening to resized images) requires that Drupal use Imagemagick as its toolkit, while Image Watermark requires PHP’s GD module… though possibly not as the toolkit? I can’t tell, because GD isn’t in my local PHP install.

image toolkit

July 22nd, 2007

Drupal wouldn’t let me change the image toolkit (at admin/settings/image-toolkit) from the built-in GD toolkit because the GD toolkit wasn’t configured correctly and stopped the preference change from saving by throwing an error. I got the pref to set in my install by hacking image.inc so that the function image_gd_settings() never generates an error (and un-hacked it right away afterwards) but didn’t do any sort of general fix. I’d submit a bug report, but right now I don’t feel like figuring out where to do it/if it would be redundant. similar to the issue “Cannot change image toolkit setting after the .inc file is removed.”

input filters

May 23rd, 2007

Lullabot on Drupal input formats/filters. filters on *output* so data storage isn’t lossy.

form results in forms

May 23rd, 2007

Drupal 5: Making forms that display their own results: do $form['#multistep'] = TRUE; and $form['#redirect'] = FALSE;.

4.7.x to 5.x changes

May 23rd, 2007

Converting 4.7.x modules to 5.x. Posts after this point will refer to Drupal 5 unless otherwise stated.

module

May 21st, 2007

it was recommended that I run my module through the coder module.

drupal IRC

May 1st, 2007

drupal IRC: where it is, guidelines.

vid?

May 1st, 2007

vid = Version ID. distinguishes between revisions of nodes (as opposed to nid, which distinguishes between nodes themselves). from the drupal.org forums.

pros/cons?

April 26th, 2007

cURL functions in PHP vs. drupal_http_request()? all I can see so far is cURL requiring an optional php extension (ie, not always available on various machines), but I’m more inclined to use it because I’m more used to the PHP documentation than the drupal documentation.

OSCMS video

March 29th, 2007

video of some of the OSCMS 2007 sessions.

OSCMS 2007: Build a CCK Module in Drupal

March 26th, 2007

session description

build a cck *field* module in drupal (to add new fields to cck content types)

hooks, options, cck features, api best practices

darrel o’pry (dopry), karen stevenson (karens)

code is online, somewhere.

making a cck module.

karen will make a really simple one.

drupal.org/node/somewhereunreadable

components of a cck module:

  • widget - how will it be displayed for input?
  • field - what will it look like in the db
  • formatters - how will it be displayed to the end user

give field a type name.

label for type of field

- spaced out -

content_format() you can do this yourself in your theme, and use any of the “formatters” available from the field’s cck module.

darrel will make another one

the code is available in drupal’s cvs… geolocation field

mentions the dprintr() function, what is it?

dopry’s demo module in the drupal cvs: drupal contrib -> head -> geolocation

OSCMS 2007: Site Structuring and Navigation in Drupal

March 26th, 2007

session description

jeremy epstein

options for structure & hierarchy. strengths and weaknesses.

users see pages, drupal sees menu callbacks

modules define the menu_hook, which lets you define callbacks at urls.

menu callbacks don’t necessarily reflect the structure that your users see on the site; don’t always relate to what users see on the site.

pages: how are they arranged?

traditionally in drupal: open and flexible. has this been a problem?

hierarchy of pages is not the only option. others:

  • chronologically (day/month/whatever)
  • tags
  • related pages (done a lot on amazon: “you may also like…”)
  • directory/index
  • browsing alphabetically
  • tag clouds

no “folder” concept in drupal. some other cmses are pretty strongly based on the file/folder metaphor, ie plone.

navigational elements:

*nix shell = open sea, no navigational elements

web = city. people are surrounded by environment/context.

some navigation devices:
  • menu trees
  • breadcrumbs (drupal doesn’t have a strict hierarchy, but breadcrumbs are a strictly hierarchal nav element.)
  • tabs
  • urls
  • search
  • previous/next/up “book” links
  • table of contents
tools in core for nav elements:
menu system (”foundation of all page hierarchy in Drupal”)
whether or not you have the menu module enabled, there’s still a menu giving structure to the site.
theming system (provides rendering for some nav elements)
book module (hierarchical structuring, not built on menu system)
not linked to other structures within drupal
taxonomy module (tagging pages, directory browsing, linking and grouping pages based on tags)
can be hierarchical, but not necessarily. can also be chaos. terms aren’t nodes.
path module (allows custom urls that may match a site’s structure.)
doesn’t automatically create urls that match your site’s hierarchy
tools in contrib:
  • taxonomy content (breadcrumbs and menu trees based on taxonomy term hierarchies
  • pathauto (automatic url generation based on whatever)
  • category (tries to bring together nodes, taxonomy/book hierarchies, menu trees, and nav elements… dubiously successful? by the session leader)
  • views module (breadcrumbs, menu trees, tabs based on results of querying the site’s content) many people think of views as just a custom query builder, but it has a lot of ways to reference the site structure.

fitting them all together

currently not built to work together.

drupal’s current navigation api

nav elements and how they work

menu trees
  • generated as blocks by the menu module
  • edit in admin/build/menu
  • hopefully the new menu system (part of drupal 6) won’t be less editable than the current version
  • customizable through the theming system
  • some modules bypass that, and build their own menu trees in blocks: bad. they make their own nav in blocks. but most modules don’t do hierarchical urls at all.
breadcrumbs
  • auto generated based on menu location.
  • location of page is determined at admin/build/menu, or is inferred from the path.
page’s system path.
  • people have talked about making an api.
  • drupal_set_breadcrumb() and menu_set_location(): “evil hacks,” because they override user [something]
tabs
  • used for up to two levels of local tasks
  • [got distracted]
urls
  • path module allows any url to be aliased with anything, which is great. internal paths are translated to the path alias.
  • api is very basic, just saves the aliases to db
  • - overhead “used to be very very very exponential” (or is this about “index aliases”?)

question: recommended best practice?

  • if it’s a small site, use the menu system. or at least, stick to the core modules. or, experiment with views.
  • you could also look at organic groups. “og is a hog. it has to check node access on every node you’re looking at.”
  • check out the menu trim module; it cuts off some of the cruft in the menu system.

dream navigation api…

all pages linked using a unified relationship api. it would define parents, children, siblings.

(me thinking: possibly also defining relationships like relating user or event nodes to story or page nodes. or a define-your-own-relationship kind of space.)

every page’s content would be customizable

a lot of pages are just menu callbacks, and they’re not editable. one way to go about this: every page as a node, and module output embedded within node pages. note: the “about us” page is a node, and editable, but the “forum” page isn’t, because it’s just a menu callback. developers don’t like this solution.

(audience talking: there should be a way to link the admin page relating to a page that is a menu callback to the callback page thing itself)

navigational elements should consistently reflect the same relationships

if someone builds this, it should be in the next drupal.

OSCMS 2007: jQuery: Making Javascript Fun Again

March 26th, 2007

session description. the slides for this talk are available at the presenter’s website.

people still hate javascript, but it is

  • imperative, functional, and oo
  • lexical scope and closures, anonymous functions
  • everything is an object
  • prototype-based inheritance
var myHash = { foo: 1, 'bar': 'two'};
// myHash.foo == 1 OR myHash['foo'] == 1

function = primitive type. this enables javascript closures. a method in an object is just a function…

var myObject = {
  foo: 1;
  bar: function () { ... } (or something?)
}

function as object constructor

var myClass = function (thing) {
  this.thing = thing;
  this.bar = function () { ... };
  return this;
};

// myClass.prototype.foo = function() { ... };

var myObject = new myClass("dork");
myObject.bar();

closure example:

function myFunc() {
  var counter = 0;
  function closureFunc() {
    counter++;
    alert(counter);
  };

  return closureFunction;
};

var closure = myfunction();
closure(); // 1
closure(); // 2

AJAX is making GET and POST requests from JS. you can send xml if you want, but it’s heavyweight. JSON = javascript object notation, simpler/lighter.

jquery doesn’t:

  • mess with js prototypes (you can extend and screw up all kinds of basic objects and fuck up other scripts that might want to run on the page.)
  • is small. uh, comparatively
  • not a purely ui lib
  • a dom-free solution

jqueries use css3/xpath selectors to find elements

(me thinking: simon willison had a script that would select elements based on their css selectors… updated version or similar more polished thing: http://bennolan.com/behaviour/

example:

$('table.prices tr:last-of-type td')

jquery methods are chainable: the query obj is stateful. method on method on method.

$('p').addClass('big').wrap('<span></span>')
.filter('.tagged').css('background','red').end()
sensible event handling
$('span.info')
 .mouseover(function () { ...})
 .mouseout(function () { ...})
...

woah: give jquery some html, and it will convert it to DOM nodes and then act on it.

$('<div></div>').hide().dostuff().appendTo('#elementidorsomething');

so chainable in jquery translates to doing an entire action without an expressed variable. bizzarre but eventually comprehensible.

there are plug-ins for jquery. they provide new chainable methods, more effects. more ui flashy junk.

drupal 5 uses jquery 1.0. you can upgrade drupal 5.0 to use jQuery 1.1, but you have to install a 1.0 compatibility plugin [jQuery plugin, not drupal].

js in a CMS:

  • cms things happen on the server side.
  • js is icing.

specific drupal features that use js: form api widgets, drupal_add_js()

“standard way of passing things from php to js”

client side: namespace your methods (how, precisely?)

drupal 5 js was rewritten with jquery

why jQuery:

  • jquery “satisfies demand for bells and whistles”
  • solid
  • community
  • plugins
  • wizardry already done

caveats:

  • accessibility
  • degrade gracefully
  • searchability
  • speed

writing fast and slow jqueries (there are ways to do both. hah.)

live demo using firebug

simple html page with image, text, hidden form

$('p')[0] // dom object

wrap that in $ for jquery obj rather than dom object:

$($('p')[0])
$('#sign-up a').click(funtion() {
  $(this).hide();
  $('#sign-up form').fadeIn('something');
});

using css3 selectors within jquery:

$('p:nth(0)').fadeOut());

see acko.net for code snippets.

color picker jquery plugin (the one in drupal 5?)

uses “thickbox”. there’s a thickbox module (for jquery). is thickbox a js library thingy? do I care?

some people use jquery to fix browser bugs. that’s dumb.

fyi, firebug is a complete debugger.

jquery is very different from other js libraries because it’s very “intrusive in the way you program” - probably because of the bizarre chaining things

jquery is pretty good at abstracting &c. you can use jquery.(things) the same way $(things) is used in the above snippets.

jquery documentation:

OSCMS 2007: FormAPI Inside Out

March 26th, 2007

session description

  • been around for a year, but not well understood
  • reasons for foms api, what it accomplishes, etc. demistify. under-the-hood life cycle. also, pictures.

first

  • first, plain html forms. very flexible.
  • then there were helper functions. to help developers. every form had to re-implement the form life cycle. security!
  • node form from drupal 4.6. forms built as plain html.
  • form api: build forms as a structure. make the workflow automatic. make doing the right thing easy.
  • drupal_get_form('form_id')
  • every form in the drupal system has a unique id. calls my_form(), spits back html
  • or, calls my_form_validate()

form life cycle:

  • create page
  • user fills out, sends back values
  • drupal_get_form('my_form')
  • checks for $_POST data
  • builds form with my_form()
  • does the validation and submit handlers
  • my_form_validate(...)
  • my_form_submit(...)
  • “magic”
  • when the form def is built: drupal_rpocess_form()
  • drupal_build_form()
  • allows others to hook_form_alter()
  • _form_builder() - weaves together form and post data. populates defaults, $_POST, builds $form_values, inserts security tokens.

misc

  • if $_POST vars come in that don’t match the structure of the form (as it is after hook_form_alter()!), they’re not considered (where?)
  • don’t use $form_values global(?). some stupid thing about having too many things that need to talk to and maniuplate $form_values, and having to make it global for that reason.

“special bits”??

  • hook_elements()
  • hook_form_alter()
  • drupal_execute()
  • you can add theme functions to forms? with hook_form_api? or something?

things to know about when altering forms:

  • #submit
  • #validate
  • #theme
  • if you don’t specify these, it automatically calls things named “my_form_submit()” etc.
  • #validate and #theme can be specified for individual form attributes! by adding your fns into those properties, you can do anything you need to do in workflow.

etc

  • multi-step forms thing that I wasn’t paying attention to.
  • more I wasn’t paying attention to.

404 pages

March 5th, 2007
  1. to create custom 404 and 403 error pages: first make a node that is the error page. note its node id. then go to admin/settings/ and expand the “error handling” section. put the node address in the corresponding box (my 404 box says “node/231″). ok!
  2. finding out the requested path: good for 404 pages. use the php snippet <?php print request_uri(); ?>. you have to set the input type on that page to let you use php.
  3. more efficient 404 handling: let apache handle some 404s rather than having drupal going through it’s whole page building rigamarole just to tell someone they can’t get what they want.

drupal-controlled file transfer

February 28th, 2007

or, setting the file system settings to “Private - files are transferred by Drupal.” discussion at drupal.org. the key bit is that anyone can still access the files if they know their url; to prevent that, you either have to put the files directory outside of the web directory, or add something like this in an .htaccess file within the files directory:

ORDER DENY,ALLOW
DENY FROM ALL
ALLOW FROM XXX.XX.XX.XXX

XXX.XX.XX.XXX is your hosts IP address; 127.0.0.1 should work fine for anyone (it does for me).

plugin I installed yesterday

February 24th, 2007

devel. mostly it shows all the db queries that are run to create a page, which looks outrageous sometimes: 140 queries for the front page, 60 for a very plain regular page.

caching problem…

February 23rd, 2007

so, the caching problem: possibly it’s because the pages are stored as binary blob data and not sent to the browser correctly, as described in this comment. super-helpful debug thread; if that’s not my problem, it might be with having something in hook_init() in a custom(ized) module. anyways, caching is off for now.

why is this happening?

February 23rd, 2007

I turned on caching at the ccrh dev drupal today, and it started serving blank pages. WHY?!?

thinking aloud

February 23rd, 2007

Drupal’s file handling is gross. Either it allows direct access to all files via the filesystem (so you can’t apply access rights to files), or it passes every file through some bit of script (more overhead for every file accessed). Theme files aren’t handled through the same mechanism (a good thing). I need some sort of file manager that can manage permissions and file locations but allows files to be attached to nodes the usual way. list of file management modules - drupal.org.

see file_create_url().

I also want something where files aren’t all dumped in the same folder.

“event” module

February 7th, 2007

Event at drupal.org

user access confusion solved

January 12th, 2007

in order for a user to create content, they have to have the “access administration pages” privilege (under the system module)

the $user object looks like this:

January 11th, 2007
stdClass Object
(
    [uid] => 1
    [name] => admin
    [pass] => **hashed password**
    [mail] => **my email address**
    [mode] => 0
    [sort] => 0
    [threshold] => 0
    [theme] =>
    [signature] =>
    [created] => 1161027521
    [access] => 1166740122
    [login] => 1166410715
    [status] => 1
    [timezone] => -25200
    [language] =>
    [picture] =>
    [init] => **another email address**
    [data] => a:5:{s:6:"submit";s:18:"Create new account";s:7:"form_id";s:13:"user_register";s:7:"contact";i:0;s:10:"form_token";s:32:"**hashed thing**";s:5:"block";a:1:{s:4:"menu";a:1:{i:107;i:1;}}}
    [sid] => **hashed thing**
    [hostname] => **ip address**
    [timestamp] => 1166740122
    [cache] => 0
    [session] => watchdog_overview_filter|s:3:"all";node_overview_filter|a:1:{i:0;a:2:{i:0;s:4:"type";i:1;s:17:"content_staff_bio";}}file_previews|a:0:{}
    [submit] => Create new account
    [form_id] => user_register
    [contact] => 0
    [form_token] => **hashed thing**
    [block] => Array
        (
            [menu] => Array
                (
                    [107] => 1
                )

        )

    [roles] => Array
        (
            [2] => authenticated user
        )

)

clicky-clicky

December 20th, 2006

I just realized that to a certain extent I’m much more comfortable throwing some php into my theme, and doing work there, than building a module that will generate a block so I can go in and clicky-clicky in drupal’s ui. and that now that I’ve built the first solution, I think it might be good to do it the second way, so *other* people can clicky-clicky.

(specifically this is in re- to “my navigation thing.”)

restricting content access

December 18th, 2006

wanting to restrict access to the board meeting minutes and board packets on our site. possible modules:

  • path access module: restrict access to parts of a site based on their path. pros: restricts the whole section. cons: if the path gets messed up, the stuff is exposed.
  • simple access module: restrict access to nodes to certain roles. pros: restricts access everywhere. checking a box would make sense to my users. cons: too granular? doesn’t hide the listing page? (can do that with views)

conclusion: simple access. I think.

images in nodes. ugh.

December 15th, 2006

writeup on attaching images to nodes: Image and Image Exact Sizes vs. Imagefield and ImageCache. using an imagefield on a custom cck content type isn’t an option for me… I’m using the standard story type. just trying to figure out how to let people put images in their posts and pages easily. (also, which wysiwyg editor to use?). I feel like these should be ‘duh’ decisions and I have just forgotten/not absorbed the answers.

find out a url

December 13th, 2006

arg() only gets parts of the internal path. drupal_get_path_alias('some/internal/path') gives you the face you want to show to the world. ex: drupal_get_path_alias('node/'.$node->nid). snippet here: customizing themes by location.

front page layout switcher

December 13th, 2006

check whether a page is the front page in a template:

<?php if ($is_front) { /* do something */ } ?>

submitted form values.

November 29th, 2006

suppressing the redirect that happens after form processing at drupal.org. also, getting to $form_values and $_POST shit. $form_values doesn’t seem to be as global as it pretends to be…

update: apparently, $form_values shouldn’t be a global, and using it is bad. or something.

forms and tables

November 28th, 2006

writing forms in tables. for when I eventually want to clean up the field prefs of cck_search to be themed into a table instead of hacked into one.

drupal phptemplate themeing hacks

November 22nd, 2006

extreme drupal theming, a series of tutorials by nick lewis.

db JOINs

November 21st, 2006

inner/left/right joins: what and why. at drupal.org. really basic, really essential, not drupal specific.

handling text safely

November 21st, 2006

wear rubber gloves!

how to handle text in a secure fashion at drupal.org. talks about check_plain() and friends.

debug

November 21st, 2006

watchdog() is good for debugging your code. (how to use watchdog())

<?php
 // snippet taken from 4.7 -- includes/bootstrap.inc
/**
 * Log a system message.
 *
 * @param $type
 *   The category to which this message belongs.
 * @param $message
 *   The message to store in the log.
 * @param $severity
 *   The severity of the message. One of the following values:
 *   - WATCHDOG_NOTICE
 *   - WATCHDOG_WARNING
 *   - WATCHDOG_ERROR
 * @param $link
 *   A link to associate with the message.
 */

function watchdog($type, $message, $severity = WATCHDOG_NOTICE, $link = NULL) { ... }
?>

still learning the forms api

November 20th, 2006

really useful example: a module with a form. at drupal.org.

using drupal_get_form()

November 20th, 2006

so first you do:

drupal_get_form('form_name', $form_variable, 'form_callback');

then you define functions form_name_validate($form_id, $form_values) and form_name_submit($form_id, $form_values) that get called when you use drupal_get_form(). so you have drupal_get_form() generate the form, then you hit submit, then drupal_get_form() uses form_name_validate() to validate the form, and if it’s ok, runs form_name_submit(), which will most likely stow the data in the database.

drupal_get_form()

November 20th, 2006

flow chart of drupal_get_form(). at a blog by a lullabot guy. need more help with this!

arg(0)

November 17th, 2006

interesting: the arg() function doesn’t seem to clean anything out of the url: if you put html in the url, and then the code does something like <?php print arg(4); ?>, then you get that html that was in the 4th (actually 5th, it starts at 0) argument printed out.

generating forms with drupal

November 15th, 2006

forms api quickstart guide, forms api.

the beginning of making a search form for a specific cck content type:

<?php
$form ['quick'] = array (
	'#type' => 'fieldset',
	'#title' => 'Quick Search',
	'#tree' => TRUE,
);

$form['quick'][$field_name] = array(
	'#type' => $field_type,
	'#title' => $field_label,
	// type specific things
);

$form['advanced'] = array (
	'#type' => 'fieldset',
	'#title' => 'Advanced Search',
	'#tree' => TRUE,
);

$form['results'] = array (
	'#type' => 'fieldset',
	'#title' => 'Results Options',
	'#tree' => TRUE,
);
?>

arg(0) gives internal urls, but still:

November 10th, 2006

lullabot on arg(0)

need to wrap my head around

November 10th, 2006

Split theme(’page’) $content into multiple sections

attaching images to posts

November 6th, 2006

some guy on how he does image uploading in posts on drupal

theme based on log in

November 6th, 2006

to check wheather someone is logged in inside a theme, use <?php if ($user->uid) {} ?>. also, you have to add global $user in the php somewhere. see this comment at drupal.org.

I find drupal’s profusion of globals unsettling.

theme by header

November 4th, 2006

lullabot on theming by http header. basically, use this snippet:

<?php
    $headers = drupal_set_header();
    if (strpos($headers, 'HTTP/1.0 404 Not Found')) {
?>

update: better to use drupal’s built-in 404 setup: 404 pages.

modules

November 3rd, 2006

modules currently enabled on a site I’m working on are:

  • *block
  • contact
  • contemplate
  • content (cck)
  • date (cck)
  • *filter
  • help
  • image
  • image_attach
  • image_exact
  • imagefield
  • manage
  • menu
  • *node
  • node_unpromote (custom)
  • nodereference (cck)
  • number (cck)
  • optionwidgets (cck)
  • page
  • path
  • pathauto
  • poormanscron
  • statistics
  • story
  • *system
  • taxonomy
  • text (cck)
  • tinymce
  • upload
  • *user
  • userreference (cck)
  • views
  • views_theme_wizard
  • views_ui
  • *watchdog

simplenews module

November 2nd, 2006

the simplenews module requires that the taxonomy module be enabled.

image

November 2nd, 2006

I installed and enabled the image module, but was getting a message that said, “Make sure you have a working image toolkit installed and enabled, for more information see: the settings page.” The settings page had no info. from various sources I found that in order to get the image module to work, I needed to install gd2 (can do via fink). will this be already installed on our server? if not, can we get it installed? otherwise, have to figure out another solution.

update: php needs to be compiled with gd2 support. I don’t plan on recompiling php right now. it can use imagemagick, too, which supposedly I have installed, but I don’t know where the hell it resides. fuck it, on to othet things.

a little info gleaned from this page on mac os x specific guidelines at drupal.org.

update: my imagemagick is at /sw/bin/convert. you need to move image.imagemagick.inc into drupal’s includes directory, and make sure the path to imagemagick on lines 16 and 68 is correct. so now the image module doesn’t throw an error. this was found at Image module with imagemagick [solution] at drupal.org. image_attatch isn’t working yet though.

tinymce

November 2nd, 2006

is a js wysiwyg editor. to install it in drupal, get both the module (tinymce at drupal.org) and the independant tinymce thing (tinymce javascript content editor). unstuff the the tinymce thing and put it inside the drupal module folder. then put the whole jumble inside drupal’s modules folder. the actual install instructions aren’t prominently linked on the tinymce project page!

modules to install

November 1st, 2006

module builder

November 1st, 2006

for the future when I possibly make a module: Module Builder: “A module which auto-generates a skeleton or “scaffolding” for a module, along with hints on how to fill them in. Useful for newbie developers to learn how hooks work, and seasoned developers who are too lazy to look up what arguments a function has to take.”

theming functions

November 1st, 2006

themeable functions. see theme.inc for more on the theming framework.

$base_path and $directories in node & block templates

November 1st, 2006

they aren’t available by default. you have to paste this snippet in at the top:

<?php $base_path = base_path(); $directory = path_to_theme(); ?>

from this post at drupal.org: difficulty with image tag inside of block template.

getting nodes as an array

October 31st, 2006

get nodes as an array for greater flexibility - drupal.org. hacking template.php.

update 12/14: this works fine on the front page and on views, but nothing at all (not the headers of the template, not anything) shows up when looking at a single node (like a page node). crap, I liked this. (what is breaking it?)

primary and secondary links

October 31st, 2006

primary and secondary links are available within page.tpl.php as arrays ($primary_links and $secondary_links). customising how the primary or secondary links are displayed - drupal.org.

menu children

October 31st, 2006

display children of current menu node - snippet at drupal.org. slightly more informed than my snippets.

pathauto problem with `variable` table

October 25th, 2006

pathauto for the “inclusionary housing policy” type wasn’t working because the ‘name’ field in the ‘variable’ table was only 48 characters–the content type name plus pathauto’s name was too long so had to be truncated to fit in, so when an ih policy was submitted, pathauto wouldn’t find a path pattern for it. solution:

ALTER TABLE variable MODIFY COLUMN `name` varchar(128) NOT NULL default '';

finding out what page/section

October 24th, 2006

use the drupal function arg(0). 0=1st, 1=2nd args, etc. more info.

theming whole pages

October 24th, 2006

variables available in page.tpl.php

log in page

October 24th, 2006

to log in, go to [drupal install]/manage/login

theming nodes

October 24th, 2006

variables available in node.tpl.php

getting the type of a node

October 24th, 2006

for use within node.tpl.php. put this at the top:

<?php
  $type = (node_invoke($node->type, 'node_info'));
?>

then use the $type variable wherever you want the (human readable) name of the node type. from: Node.tpl.php at drupal.org.

ways to set up navigation in drupal

October 24th, 2006

choices in navigation

to custom-theme a node type

October 23rd, 2006

make a template called “node-type.tpl.php”. for cck circa aug 2006, this is ‘node-content_cust_content_name.tpl.php’. then put this in to find out what info is available:

<pre><?php print_r($node); ?></pre>

gleaned from creating a template handbook.

views module patch

October 23rd, 2006

cck fields with ‘multiple’ values result in duplicate nodes showing up in a view. this patch is supposed to fix it: content_views.inc_2.patch. (my first drupal.org comment there! for the same issue, see also: issue discussed first here). not sure if it actually does fix it. cli syntax to patch a file (patches in place, make a backup):

$ patch originalfile patchfile

man patch

patched eval, local dev, and ccrh drupal installs.

where modules are installed

October 23rd, 2006

installed modules and themes are stored in the table ’system’:

mysql> describe system;
+----------------+--------------+------+-----+---------+-------+
| Field          | Type         | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+-------+
| filename       | varchar(255) |      | PRI |         |       |
| name           | varchar(255) |      |     |         |       |
| type           | varchar(255) |      |     |         |       |
| description    | varchar(255) |      |     |         |       |
| status         | int(2)       |      |     | 0       |       |
| throttle       | tinyint(1)   |      |     | 0       |       |
| bootstrap      | int(2)       |      |     | 0       |       |
| schema_version | smallint(3)  |      |     | -1      |       |
| weight         | int(2)       |      | MUL | 0       |       |
+----------------+--------------+------+-----+---------+-------+

modules are registered there when they are first installed; if you want to do a fresh install of a module (say, its tables got munged up), you need to drop its tables AND remove its entry from the ’system’ table.

gleaned from this handbook article: resetting the views module completely.

module creation

October 20th, 2006

I was reading the tutorial on creating a module for drupla, and started writing this annotated module boilerplate, for a module called “modulename.module”:

<?php
/* $Id */

/**
 * HELP HOOK
 * $section variable provides context for help: where in Drupal or the module
 * are we looking for help?
 * - recommended to process this with a switch statement.
 * more help hook info: http://api.drupal.org/api/4.7/function/hook_help
 */

function modulename_help($section='') {

	$output = '';

	switch ($section) {
		case "admin/modules#description":
			$output = t("module description for modules admin panel");
			break;
		}

		return $output;
} // function modulename_help

/**
 * PERMISSIONS HOOK
 * valid permissions for this module, returns an array of valid permissions
 * more permissions hook info: http://api.drupal.org/api/4.7/function/hook_perm
 */

function modulename_perm() {
	return array('access content', 'administer modulename');
} // function modulename_perm

/**
 * BLOCK CONTENT
 * generate html for the modulename block
 * @param op the operation from the URL
 * @param delta offset
 * @returns block HTML
 * more info on the block hook: http://api.drupal.org/api/4.7/function/hook_block
 */
function modulename_block($op='list', $delta=0) {
	// listing of blocks, such as on the admin/block page
	if ($op == "list") {
		$block[0]["info"] = t('module name...');
		return $block;
	}
	else if ($op == 'view') {
		// lala... stuff goes here.
	}

} // end modulename_block

/* this is only the beginning... */
?>

Content Templates module

October 20th, 2006

Content Templates module: “allows modification of Drupal’s teaser and body fields using administrator defined templates. These templates use PHP code and all of the node object variables are available for use in the template. An example node object is displayed and it is as simple as clicking on its properties to add them to the current template.” hah, it’s also called “contemplate.” especially useful with cck, but can be used with any node type.

news items unpublishing

October 20th, 2006

the workflow module (which requires the actions module) might do the job of archiving (rather than unpublishing, like node expire) items after a certain date. possibly if it doesn’t out-of-the-box, I could also hack node-expire to be ‘node-un-premote-to-front-page’.

views for searching custom content types

October 20th, 2006

sweet! I can use the filters part of the views module to make my custom IH Policy content type searchable! Views module documentation.

“10 Drupal Modules You Can’t Live Without”

October 20th, 2006

Probably half of which I will be using. 10 Drupal Modules You Can’t Live Without | Nick Lewis: The Blog

cck field extension

October 20th, 2006

imagefield.module: “provides an image field to cck content types.” possibly will use it to hold a graph in the IH policy content type.

upgrading drupal

October 19th, 2006

summary of updating handbook.

  1. back up site and database:
    1. turn off all non-core modoles (note which ones)
    2. change theme to bluemarine (note theme configuration)
    3. command line:
      cp -r drupal_site/ drupal_bak/
    4. dowload drupalsqldump.sh.
    5. do something like this:
    6. chmod +x drupalsqldump.sh
      ./drupalsqldump.sh drupal_site/sites/defaolt/settings.php > drupal_bak/backup.sql
    7. gui: download all files.
    8. export database (selecting all, with “structure” and “data”). name the file backup.sql and put it in drupal_bak
    9. * possibly make a test site (copy backup files, database, change config settings. upgrade the copy first). see creating a test site.
  2. put new files in place:
    1. replace all drupal files
    2. copy .htaccess and the files directory to the new install.
    3. copy the $db_url, $base_url, and $db_prefix lines from sites/defaolt/settings.php to the new sites/defaolt/settings.php file.
  3. update database:
    1. you shoold have been logged in as USER 1 (the admin user. if not, see “running update.php“)
    2. run update.php: go to www.drupalsite.com/update.php
  4. put the old back in the new:
    1. put old files back in place.
    2. move custom themes, non-core and other custom modoles, from backup to fresh drupal.
  5. extra things to think of:
    1. unique steps for this site, convert cutsom modoles to new version, manually configure special database things
    2. remove: install.php, update.php. CHANGELOG.txt, INSTALL.txt, LICENSE.txt, MAINTAINERS.txt, UPGRADE.txt.
  6. test:
    1. try common tasks
    2. possibly check for file not found errors (testing the new site)
    3. keep an eye on the logs

my theme config

October 19th, 2006

enabled: “manage” (same as bluemarine) and “mytemp”, default “mytemp”.

enabled drupal modules

October 19th, 2006

at the moment:

  • contact
  • content (cck)
  • help
  • manage
  • menu
  • nodereference
  • number
  • optionwidgets
  • page
  • path
  • pathauto
  • profile
  • search
  • statistics
  • story
  • text
  • upload
  • userreference
  • views
  • views_theme_wizard
  • views_ui

getting nested menu items as seperate lists

October 19th, 2006
<?php
$i = 1;
$m = Array();
while ($m = menu_primary_links($i)) {
	print theme_menu_links($m);
	print "rr";
	$i++;
}
?>

prints out every bunch of menus down to where you’re currently at in seperate lists.

getting menu info about the current page

October 19th, 2006

<?php
print menu_get_active_title(); // name of most local currently active menu item
print menu_get_active_nontask_item(); // menu id of most local currently active menu item
?>

how to generate the “local tasks” tabs

October 18th, 2006

<?php print theme_menu_local_tasks(menu_get_local_tasks()); ?>

“local tasks” are things like view, edit, track. they are usu. styled as tabs. menu_get_local_tasks() gets the menu structure in an array.

how to generate a menu

October 18th, 2006

<?php print theme_menu_tree($mid); ?>

where $mid is a menu id (look in the table ‘menu’… for menu items pointing to a top level path, try SELECT * FROM drupal.menu WHERE path NOT LIKE '%/%';)

menu_secondary_links() not helpful

October 17th, 2006

if I set “menu containing secondary links” to my main sections menu (”other sections” right now) in admin/settings/menu, then this prints out a list of the second layer of menu items–the menu items for the section you’re in:

<?php
	$section_menu = menu_secondary_links();
	print "<ul>r";
	foreach ($section_menu as $mi) {
		print "<li>$mi</li>r";
	}
	print "</ul>r";
?>

however, it only goes one layer deep, which is no good. looks like I’ll have to generate and theme my own menu-data-structure. fuck. If I do, I’ll probably hack it together so it will only work with my implementation (sucky way to bother coding something). and I won’t have niceities like caching and themeing… though maybe. fuckity-fuck, why hasn’t someone else written this?

secondary menu items

October 17th, 2006

this function may be very useful: menu_secondary_links() (especially if I could figure out how to build a menu from it/theme it). it’s from menu.module. menu system API reference.