Blog makina

Share and options

Contenu exporté vers le blog

Code snippet: current OG context to node creation links

Simple use case of the day : when you deal with Organic Groups in Drupal, you might want your users to be able to create nodes in their groups without dealing with the infamous audience checkboxes.

A simple solution is to use the links from the Navigation menu. In order for OG to be able to add a node as post in a group, it needs to find the gids[] GET parameter.

An ugly, but really efficient solution is to use the custom_url_rewrite_outbound() function to alter node/add/* links and enforce the gids[] parameter if the user is currently is in a group context.

Le spam traduit en français du jour

Celui là me faut beaucoup rire :

Solution pour le problème de mâle délicat

Notez que j'ai volontairement mal placé le mot "délicat", je trouvais ça beaucoup plus drôle dans ce sens là.

Le spam traduit en français du jour

À partir de ce jour, j'ai pris la décision de traduire, régulièrement, un spam reçu sur une de mes boites mail en français. Le mail du jour est :

Les légendaires pillules sexuelles en ligne.

Bien que dégoûté d'en recevoir autant, environ une cinquantaine par jours, dont seulement 3 ou 4 d'entre eux passant mon spam assassin, je dois avouer qu'il me font parfois bien rire.

De la bonne utilisation de strtr()

Essayez un jour de taper ceci :

= "This container is currently being edited by %account";
$lockMessage = strtr($lockMessage, '%account', 'Anonymous');

Amusons nous avec PHP, aujourd'hui : le JSON et le console

Le petit problème du jour est le suivant : dans une application fortement AJAX, jQuery en client side, PHP en server side, j'ai besoin d'effectuer le debug de requêtes AJAX provenant du client en POST contenant du JSON, et le retour du serveur, contenant, du JSON aussi!

Pour ceci, on pourrait utiliser Firebug, que tout le monde connait bien, mais ne m'occupant pas de la partie JS, mais du code PHP serveur, j'ai pas envie d'inspecter 3000 lignes de JS pour mettre un break point au bon endroit.

Pour ceci, petit feinte, utiliser l'onglet Console de Firebug, et PHP en command line.

Tip of the day, get a views row primary key value

This is often a problem when you pragmatically manipulate views row's : finding the primary key value of the current row being explored.
Let's have an example : A node base table based view.

// Load the view, and stick to default display for sample purpose.
$view = views_get_view('my_node_view');
// Then, execute it.
// You will set some other options here, like limit, pager, offset.

What then?

Code snippet: human readable to machine name

This PHP code snippet compute nice machine name (i.e. with only alpha numerical characters, keeping inside hyphens) from a formated human readable name.

Useful for some automatic machine name identifiers computing from human readable arbitrary titles, I use it sometime in Drupal modules.

* Helper that generates a machine name using a provided human readable name.
* @param string $human_name
*   Human readable name.
* @return string
*   Machine name cleaned-up of any special chars.
function human_to_machine($human_name) {
  ), array(
'-', '-', '', ''), $human_name));

A simple (and ugly) time-saving line of code

Update on Mai, 28 : Added a new code snippet.

Sometimes, when you are trying to debug PHP code, you'll get an ugly WSOD, without any error messages in PHP error log.

When this happens, it's always really difficult to find out why. The lack of message tells you that you you didn't wrote something that bad, but bad enougth for the framework you are working with to partially catch your error without really crashing.

So, how can you resolve this?

New on twitter!

And yes, I did it because I met a bunch of french Drupalist people which intensively use twitter. I must admit this is kinda fun. You can follow me at
I'm trying the Gwibber gnome social network aggregation software, seems good.

That's it, a tiny post. See you soon for some technical junk posts about Drupal weirds stuff!

Personal reminder about Drupal's settings.php

Because I often duplicate a production site on a local machine in order to do some debugging/bugfixes, I like everything to be ready the sooner as possible without having to do a lot of clicks.

Here is how I override values in my custom settings.php file instead of loosing time clicking into the administration pages or even doing configuration alteration with Drush.

Here is a common production site settings.php $conf variable alteration :