June 2014

Drupal Module: Watchdog Event Extras

When checking the logs on the Drupal sites I run I often find myself copying the IP and searching it on google. Most of the time it is when I'm looking at a page not found or login attempt failure and I would like to know if these came from some sort of spam or a legitimate user. This process became a little tedious, so I created the Watchdog Event Extras module.

Basically what the module does is overrides the standard drupal log event page, outputting the same and adding a drupal_alter()
call. At the moment the module includes two sub modules, the first of which adds geolocation data derived from the hostname and the freegeoip.net web service with the second adding data from the stopforumspam.com web service.

Any other module can also add data to the report page by implementing MYMODULE_watchdog_event_extras_alter(&$rows, $dblog)

Cheick it out https://www.drupal.org/project/watchdog_event_extras

Also, don't forget to checkout the Link Favicon Formatter module if you ever needed to add a site favicon to a link field: https://www.drupal.org/project/link_favicon_formatter

My Turbosquid 3d models and textures are now free to download

I have recently made all my assets on Turbosquid free. Some of them have been free all along but as the ones that were not free were not really selling anyway, they might as well be free. The freebies include:

  • a wolfman model
  • a lowpoly demon which is rigged, textured and animated
  • an Australian army tileable texture
  • and a tileable paver texture with normal map

Please credit me if you use these models :)

Changing the Inline Entity Form autocomplete field to a select list

The Inline Entity Form module for Drupal is an awesome module. Most people probably have experienced using it with Drupal Commerce, but it can be used when ever an Entity Reference field is used. I have personally used it on many projects, most of which were not commerce related.

Sometimes though, the autocomplete field to select an existing entity is not appropriate, say if you only have a few entities that can be referenced.

Luckily though we can make use of the hook that the Inline Entity Form module provides which is "HOOK_inline_entity_form_reference_form_alter(&$reference_form, &$form_state)".

Below is an example of how to change all the autocomplete fields to select lists when the reference field references any type of node.

 function MYMODULE_inline_entity_form_reference_form_alter(&$reference_form, &$form_state) { 
// change the entity reference 'add more' autocomplete into a select list
if($reference_form['#entity_type'] == 'node') { // only change the forms that reference a node
$field = field_info_field($reference_form['#parents'][0]);
$nodes = node_load_multiple(array(), array('type' => reset($field['settings']['handler_settings']['target_bundles'])));
$options = array();
foreach($nodes as $node){
$options[$node->title.' ('.$node->nid.')'] = $node->title;
$reference_form['entity_id']['#type'] = 'select';
$reference_form['entity_id']['#options'] = $options;