Wednesday, June 23, 2010

Hákarl

Mijn baas kwam eens een keer op het werk met een lekkere snack van zijn moederland, Ijsland.

Hij ging bij iedereen langs, opende het kleine bakje met -het leken wel toffeetjes of iets dergelijks- Hákarl, echter de geur deed anders vermoeden.

Hij deed het goed, waarschuwde niet, zodat de onachtzame collega een blokje in de handen had zonder het ergste te vermoeden.

De geur deed menigeen bijna kokhalzen.

Visgeur heeft voor mij zowiezo al een alarmerend effect, maar dit sloeg werkelijk alles. Alleen het openen van het bakje was al genoeg om de rest van de dag de ramen op kantoor open te houden.

Hákarl staat bij slechts weinig restaurants in IJsland op de kaart, waarschijnlijk om de gasten niet weg te jagen.

Indien men de hákarl door heeft weten te slikken, wordt dit in de regel gevolgd door een flinke slok brennivín, een traditioneel gebrouwen soort jenever. Het eten van hákarl wordt door de IJslanders geassocieerd met moed, kracht en durf.

Aangezien ik zo laf ben als een coyote, hoefde ik de schijn niet op te houden. Bovendien ben ik vegetarier, wat in dit geval ook een mooi excuus was.

Tuesday, October 6, 2009

User 0

I had a problem with Drupal once. I couldn't seem to get a message from drupal_set_message when a user registered on my site.

I added a print in the user.module:


function user_register_submit($form, &$form_state) {
...
if ($notify) {
...
}
else {
drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.'));
print 'xxxxxx';
$form_state['redirect'] = '';
return;
}
}
...

}


It prints 'xxxxx';

A var_dump of the $_SESSION variable gave the status message, which drupal_set_message didn't display. So it was definitely coming at the right place!

I've uninstalled all my modules, only core remained, and used Garland as a theme.

Furthermore, I had installed a fresh Drupal installation, and there it gives me a nice status message.

Then i compared my .htaccess and Drupal's, from the fresh install. Modified mine to make them equal.

Nothing worked.

Until I found out that user 0 was missing. That was the cause. But how does that effect the $_SESSION variable in Drupal?

I posted my question on StackOverFlow and I got the solution (link to the post itself):

Drupal sessions are linked by ID number (you can see this in the session table in the database if you look) to the user. Drupal also has it's own session handling functions, and one of those is a check to see if the current session is associated with a valid user account - and for anonymous users, that is the user 0 - (it doesn't matter if multiple sessions are open per user - which is certainly what happens when so many anonymous users visit your site).

If Drupal does not find a valid user for the current session, then the session is regenerated anew - meaning the previous information is lost.

by HorusKol

Wednesday, September 23, 2009

WOD (White screen Of Death)

Once in a while, when you copy your local Drupal environment to a test or production environment, a WOD appears, and you have no clue why.
A fatal error occured, and all you have to do is put this in your settings.php (usually in sites/default):
ini_set('display_errors', 1);

Then you will see your error.

Customize exposed views forms

Suppose you want to alter a form you created by using views2 exposed form.
typically, you will get a submit button with the value 'Apply', instead of, for instance, 'Search'.
How to alter this value?

What you need is drupal's hook form_alter.

In your module, create the following function:


function mymodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == '?') {
//what you want to do
}
}


To know your form_id, just print it:


function mymodule_form_alter(&$form, $form_state, $form_id) {
var_dump($form_id);
if ($form_id == '?') {
//what you want to do
}
}


Then you will see that, your form_id is views_exposed_form.
That is not only for your exposed view form, but for all exposed view forms.
I think this is a design flaw, because you expect at least your view's name and display type in it.

Anyway, now that we have our form_id, let's do something with our form. We want to alter the submit button's value. But how?
We simply print the form to see where that value is hiding:


function mymodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'views_exposed_form') {
var_dump($form);
}
}


You will get a lot of array values on your screen now, so best is to view the source code of the page (Ctrl+U in firefox).
Searching for the 'submit' button gives:

"submit" ["#value"]=> string(5) "Apply"


So all we have to do is

function mymodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'views_exposed_form') {
$form['submit']['#value'] = t('Search');
}
}


And we're done!