Last week, I managed to achieve the prestigious Drupal 9 Grandmaster title. This week I completed the puzzle with Drupal 7, because legacy projects need love and attention as well.
Had some performance issues with a client, recently. The server is an absolute beast, and should be able to easily handle the single website hosted on it. Alas, pages took forever to load (D7). A simple top showed that load was at about 60, and CPU utilization was at 10% for user and ... 95% for system. Wait what?
Field Collections are basically multifields in Drupal 7. They're so much user-friendlier than having referenced nodes, and so much lighter. However, if you try to add items to them (that is, an unlimited field collection field) in hook_node_presave , you get stuck in an endless loop. If you have XDebug or similar, you will see the extremely unhelpful message " Maximum function nesting level of '100' reached, aborting!". So what now?
One of the things I love about Drupal is the taxonomy system. It's convenient and stable... except when it's not. I got 404s for the term URLs (both system and alias) and the cryptic message "Notice: Undefined index: href in menu_local_tasks() (row 1973 in path2site/includes/menu.inc).". Well, here's what worked.
We all know that Drupal provides the FormAPI, in which very powerful form elements exist (in our case, the tableselect element). This magical element behaves like a table, but has a checkbox for each line, and associated JS/CSS to handle checking rows. But it is normally impossible to add additional form elements on each row ( there have been many workarounds, but all seem hackish) due to the way Drupal handles form submission. This is how to have a clean (and simple!) way to go around those restrictions.