You are here

Drupal

Pruning the Taxonomy Term Tree Widget

Corey Pennycuff's picture
taxonomy_term_tree_widget.png
Taxonomy Term Tree Widget
Image from drupal.org

Taxonomy is a great tool in Drupal for categorizing information, unfortunately it is not often very "pretty" for the end user to interact with. Taxonomy Term Tree Widget addresses this deficiency by generating a pleasant, familiar tree structure from the target vocabulary's terms and their corresponding hierarchies. There is one problem, however, and that is that it is very difficult to filter the visible terms programmatically. The list can be filtered using a view (a setting accessible in the widget configuration form) however such a simplistic approach may not be flexible enough for most applications.

Make HTML Form Navigation Behave Like A Spreadsheet

Corey Pennycuff's picture

If necessity is the mother of invention, then clients are the source for interesting programming problems, and the need to solve those problems are a never-ending source of discovery for programmers. Such was the case for a recent project in which a lot of data had to be entered quickly and efficiently into an HTML form. The customer was accustomed to using spreadsheets, and wanted, most specifically, for the form to replicate the action of a spreadsheet when pressing enter. To put it plainly, they wanted the focus to go to the next row when they pressed enter.

The normal behavior for a form is that the browser will submit the form when enter is pressed (unless the element is a multi-line text area). Preventing this is easy enough using jQuery's keypress() event and listening and acting on the keyboard input as appropriate.

HTML Encoding in Drupal Entity References

Corey Pennycuff's picture
double-escape.png
Double Encoding Issue

Building complex websites with Drupal will undoubtedly require you to use the Entity Reference module. Overall, this is a great module with a lot of power and flexibility. It does have one fault, however, and that is that Entity titles are double-encoded when being shown in select boxes, as you can see here. This is nothing more than a small annoyance for experienced users, but show this to a customer and they will swear that something is broken!

As it turns out, this is a known problem, and at the time of this writing no general solution has been developed, due to issues beyond the scope of this short blog post. I'm just going to tell you how to fix it for yourself! All that is needed is a simple hook_form_alter() that will cycle through the options and remove the extra encoding, as demonstrated here in our ficticious misc module.

Users Creating Users in Drupal

Corey Pennycuff's picture

One of the biggest mistakes that I feel that Drupal has made is that it is difficult for non-administrators to create accounts for other users.  While at first blush this seems appropriate, there are many, many valid reasons that users should be able to create accounts on behalf of other people.  The problem is that, in all versions of Drupal (at least 5-8) there is a call to drupal_goto() inside the form generation function that is executed unless the user has the "administer users" permission.

This is bad!  I actually feel that this is a defect, in that the code should not perform a redirect when generating a form!  Returning nothing would be much preferred!

That being said, I have had 3 sites in as many months that needed the functionality of one individual (not an administrator) creating an account for another user.  The general method presented here is not without difficulty, as you may have to do other altering of the form in order to get it to do everything that you want it to, but the code shown here will provide the basic functionality.

Pages

Subscribe to RSS - Drupal