HTML Encoding in Drupal Entity References

Corey Pennycuff's picture
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.

An Inefficiency in the PHP Source Code?

Corey Pennycuff's picture

I was browsing through the PHP source code the other day when two things struck me. First, I must be weird for being curious enough to look up the source code. Second, I found an inefficiency in a seemingly straightforward function that I would like to discuss here.

In the PHP source code for quote_print.c, the first function is php_hex2int(), which I will provide here:

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.


Subscribe to CS Crunch RSS