tag:blogger.com,1999:blog-52186847914522199432023-11-15T15:19:32.384+00:00Drupal 7-ishAdventures in Drupal 7Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.comBlogger47125tag:blogger.com,1999:blog-5218684791452219943.post-13304789573778969202014-03-05T12:05:00.002+00:002014-03-05T12:05:56.626+00:00Debugging quickie: ObjectsHow do you display the contents of an object that has private and protected properties - which means dpm($object) doesn't give you what you want?
You could do this:
dpm('<pre>' . print_r($object, TRUE) . '</pre>');
But that's a lot to type and you get a huge horrible list (particularly if it's a View object).
Try this instead:
dpm((array) $object);
Works a treat.
And while Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com0tag:blogger.com,1999:blog-5218684791452219943.post-48849528001880924402013-09-23T08:10:00.000+01:002013-09-23T08:19:57.657+01:00Field Complete and Profile2So I thought I'd promote the latest dev version of my Field Complete module to a release candidate yesterday. There were two reasons for this: (a) it's pretty solid, and (b) people are more likely to use it if it's out of dev.
It wasn't a mistake. Within a couple of hours I had a new bug report: Doesn't work with Profile2.
Which surprised me a lot, why on earth would it not work with a popular Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com2tag:blogger.com,1999:blog-5218684791452219943.post-45503528859734402672013-08-09T16:45:00.000+01:002013-08-10T18:08:01.537+01:00The History of the Field Complete moduleA couple of months ago I was contracted to work on a project for a large UK organisation that provides accreditation for university, and other, further education courses of a certain type. The site had already been mostly designed and built so I had no say in its overall structure. Suffice to say: I wouldn't have done it like that.
Still, we play the hand we're dealt.
The nature of the project Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com2tag:blogger.com,1999:blog-5218684791452219943.post-48010427561314302522013-07-11T09:21:00.000+01:002013-07-11T09:21:28.971+01:00Export UI, Features and TaxonomyHere's a quicky. Let's say you've created some exportable content (using CTools) which references a term ID and you have to go from your dev site to the production site. And your taxonomy is also being exported using UUID.
Somehow you have to tie them together because sure as eggs is eggs the term IDs created on the production site are not going to be the same as the local ones. That's why you Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com0tag:blogger.com,1999:blog-5218684791452219943.post-6072265958070065462013-07-05T13:07:00.001+01:002013-07-05T13:09:21.453+01:00Entity Reference Views Widget plus Organic Groups NightmareLet's suppose you are using the Entity Reference Views Widget to display items to be included in an Entity Reference field. This is actually quite a cool module while being a little awkward to use - essentially it gives you a views listing of candidate entities to add, with an AJAX-driven checkbox: click the box and the entity gets moved to the list on the left to display what's been chosen.Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com0tag:blogger.com,1999:blog-5218684791452219943.post-70169456772303827932013-04-13T16:50:00.000+01:002013-04-13T16:50:31.450+01:00Feed Sources and Self Nodes and Bears (oh my)Seems it's been nearly a year since I last posted something. I can only say that I have been tied up with Drupal 6 projects and uninspiring Drupal 7 ones. However something interesting came up with a project of my own over the last day or so. So here we are:
The project in question involves creating a meta-search site on a specific subject with data gathered from various sites. Some of those Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com3tag:blogger.com,1999:blog-5218684791452219943.post-63286920694033359392012-07-25T13:46:00.003+01:002012-07-25T13:47:04.967+01:00Form API and AJAX callbacks
Here's a piece of information that's well hidden.
If you're using Drupal's AJAX functionality with forms - but you don't actually want to change the form but instead do other stuff on the page, you may run into trouble because there's something that's not clearly explained about the AJAX callback function in your PHP code.
You know you can add this:
$form['tickbox'] = array(
'#type' =&Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com0tag:blogger.com,1999:blog-5218684791452219943.post-84553550993503941022012-07-22T15:31:00.005+01:002012-07-22T17:12:11.716+01:00jQuery publish/subscribe custom eventsThere seems to be a stuck idea with respect to jQuery which demands binding custom events and their functions to a specific DOM object (like 'document' or 'body') and triggering the event on that object which then tells whatever objects might want to know about the event using another event.
There's an example of this here: http://stackoverflow.com/questions/399867/custom-events-in-jquery&Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com0tag:blogger.com,1999:blog-5218684791452219943.post-76533856340012265082012-07-09T16:46:00.000+01:002012-07-09T21:53:51.085+01:00Search API, Facet API and Display SuiteJust spent most of the day tracking down a nasty little issue involving these three modules.
Let's face it Search API with Facet API (and all the Search API support modules) are brilliant, the core Search is very difficult to customise and you usually have to end up with nasty core hacks if you want to do anything clever.
Search API on the other hand is lovely, and Facet API is just great with Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com1tag:blogger.com,1999:blog-5218684791452219943.post-45349124660459375962012-07-04T17:36:00.000+01:002012-07-04T17:36:47.148+01:00Changing view_mode mid-streamIn my current contract I have to display a hierarchy of complex taxonomy terms - each one as a page with relevant data hanging off it. There are three levels to the taxonomy: Level 1 displays one set of data and links, Level 2 is never displayed on its own (which is something I'll have to take care of) and Level 3 has a different page structure again.
Different page layouts means Display Suite (Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com0tag:blogger.com,1999:blog-5218684791452219943.post-66332840623404760772012-05-29T22:35:00.000+01:002012-05-29T22:35:06.542+01:00Then three come all at onceI have been doing some work on the field_extract module, a few minor fix-ups most of which wouldn't be noticed and added support for the entityreference field. You can find this module here: http://drupal.org/project/field_extract
Someone I worked with recently has put out my "deeplink" module which allows otherwise hidden content to be made available on a specific trackable URL. My version was Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com0tag:blogger.com,1999:blog-5218684791452219943.post-43468596879130303072012-04-12T10:03:00.001+01:002012-04-12T10:03:40.697+01:00Entities vs NodesFor the last six months I've been working on a Drupal 6 site professionally, but developing a couple of personal Drupal 7 sites. However I haven't been going into D7 in any great detail - except for developing entities.
Now I've moved contracts and I'm developing a new Drupal 7 site to replace an older non-Drupal site with lots of additional facilities. And the Drupal implementation is entirely Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com2tag:blogger.com,1999:blog-5218684791452219943.post-57441341294436473912012-02-02T19:27:00.000+00:002012-02-02T19:27:07.384+00:00Cleaning the watchdog
As a Drupal developer - do you do this?
Do you go through watchdog, find every error and fix it? You probably should - and here's why:
If there's even just a Notice, it means something's not right - checking it out might reveal something far more important.
Every error that goes to Watchdog is consuming valuable processing time. I had an instance quite recently where an error in a third partyAdaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com0tag:blogger.com,1999:blog-5218684791452219943.post-30930309535562419052012-01-30T14:51:00.001+00:002012-01-30T14:51:50.355+00:00Little debugging aidI had been having a real problem tracking down a PHP error in Drupal which was passing an array to htmlspecialchars() in check_plain() instead of a string. I needed to use debug_backtrace() but the issue was related to Views which meant that the arguments being passed at higher levels were catastrophically huge.
It was a real problem, using krumo just resulted in out-of-memory errors. And the Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com0tag:blogger.com,1999:blog-5218684791452219943.post-67272817455135683142012-01-26T11:46:00.000+00:002012-01-26T11:46:43.033+00:00Where the **** is it?You know how it is? You have this complex and massive PHP structure with recursive elements and somewhere in all that is a value you're looking for. Views object I'm looking at you!
Here's a PHP routine, which is not Drupal specific, that will dig down into an object to find the property or array item you're looking for - and it avoids recursion by keeping a list of structures it's already Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com0tag:blogger.com,1999:blog-5218684791452219943.post-1471712524773397532012-01-25T23:35:00.000+00:002012-01-25T23:35:16.496+00:00Wiki filter for Drupal
One of the known problems with Drupal is no Wiki module. It is possible to put together a Wiki using various resources but the biggest stumbling block is the text filter.
There have been attempts and some successes. The current perceived wisdom is to use FlexiFilter - sorry but it's just too cumbersome. In fact nightmarish.
And I needed a Wiki filter for a project so this evening I spent 5 Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com2tag:blogger.com,1999:blog-5218684791452219943.post-81991425591065509942012-01-21T18:42:00.000+00:002012-01-21T18:42:16.852+00:00Stable Field Value Extraction module releasedOkay, after weeks of nobody complaining about any aspect of my field_extract module I have finally got around to issuing the code as the full stable version. Hurray.
Now because I'm lazy I use Eclipse for development purposes - I know, I know, how can I be a proper developer if I don't use Linux and Vim? Well, I don't. I was using command line before you were born (unless you were born before Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com0tag:blogger.com,1999:blog-5218684791452219943.post-23621259565494078832011-12-15T09:28:00.002+00:002011-12-15T09:30:52.551+00:00MD5s as IDsWhile there is the chance of duplication it can be handy to use MD5s for creating a "unique" ID for strings. I had this in my current project but I've done it before and there is a potential problem which is more likely than duplicate IDs.
There is a chance that you'll get an MD5 that begins with a zero and, potentially even worse, one that begins with a zero and is all decimal numeric (does notAdaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com3tag:blogger.com,1999:blog-5218684791452219943.post-33462050915521677932011-11-16T19:34:00.001+00:002011-11-16T19:43:05.158+00:00SssshI've not posted recently because my current job involves Drupal 6 so I've done virtually no D7 work for a while. However I do have a new set of modules for developers coming soon which will be in both D6 and D7 varieties.
Essentially it's a system that does a similar job to CTools plugins but is lightweight and standalone. It's very good for de-coupling dependent custom modules, essentially veryAdaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com0tag:blogger.com,1999:blog-5218684791452219943.post-13073311644099661802011-09-26T14:38:00.001+01:002011-09-26T14:38:09.101+01:00Automatic file downloadI have a personal project I'm working on which requires an automatic download link. You know the sort of thing - like you get on SourceForge: "Your file will download in x seconds". And then the file download dialog pops up.
All the solutions for this are JavaScript - and if you want a countdown then JS is the way to go. But I didn't want JavaScript.
The basic part of the trick isn't Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com0tag:blogger.com,1999:blog-5218684791452219943.post-55629341456359521422011-09-11T12:56:00.000+01:002013-04-13T16:53:31.906+01:00field_extract module in betaEDIT: Now out of beta. Fully implemented.
EDIT: You can now get the module from http://drupal.org/project/field_extract and it works properly with Drush.
My incredibly useful field_extract module is now available on drupal.org. I am slightly embarrassed because something went wrong in the project creation process so the actual URL is:
http://drupal.org/project/1158878
And when you Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com3tag:blogger.com,1999:blog-5218684791452219943.post-62629806639352092782011-09-07T09:16:00.000+01:002011-09-07T09:16:43.346+01:00Reducing the footprintSorry I haven't blogged in a while, I have been working very hard on commercial D7 sites in my day job but haven't really come across anything spectacularly D7 I wanted to talk about.
So here's something unspectacular but quite important, and applies almost as much to D6 as D7.
Every module eats memory. Every x.module file (for enabled modules) gets loaded for every access (well, let's ignore Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com2tag:blogger.com,1999:blog-5218684791452219943.post-13624482135999890762011-06-12T09:50:00.002+01:002011-06-17T11:06:24.196+01:00Vocabulary by machine name, taxonomy_get_tree() and $user(Amended on 17 Jul 2011 to replace reloading entire entities with using field_attach_load().)
Getting the ID of a vocabulary has long been a problem in Drupal but Drupal 7 goes a long way to resolving that:
$voc = taxonomy_vocabulary_machine_name_load('vocab_machine_name');
And you've got it.
However if you want to load a taxonomy_tree you still have to use the vocabulary ID so you run Adaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com6tag:blogger.com,1999:blog-5218684791452219943.post-39340984223667550922011-06-09T13:32:00.001+01:002011-06-09T15:21:32.263+01:00Contextual linksToday wasn't the first time I've had a fight with contextual links, but I decided that this time I would get to the bottom of why they are such a pain to implement.
What's a contextual link? The little on-screen tools that let you jump to editing/deleting nodes, views, configure blocks and so on. (But not taxonomy - however I'll get to that later.)
The idea behind a contextual link is as simpleAdaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com1tag:blogger.com,1999:blog-5218684791452219943.post-44217623474367164082011-05-04T10:57:00.000+01:002011-05-04T10:57:06.213+01:00Search Query bugI've just issued a bug report and patch for a problem with the Search Query class. It's not a huge bug but it prevented me from doing something I needed to do: add some restrictions to a Search Query.
There are two ways of modifying queries in Drupal 7, you can either use a generic "hook_query_alter()" or use "hook_query_TAG_alter()". Tags are a way of telling other modules what a query is aboutAdaddinsanehttp://www.blogger.com/profile/10577587188266580561noreply@blogger.com0