Web Mechanic Blog

Sorting by Taxonomy Terms in Views

Submitted by Matthew on Fri, 04/21/2017 - 15:26

Have you ever had to sort a view of nodes by a referenced taxonomy term?  In our system, each staff member is entered as a separate node, containing the staff member's name, position and email address, and also containing the department the staff member works in.  The department is a taxonomy reference field.  We then have a view that pulls in each staff member's node, organized by department, and the departments are listed alphabetically.

Notes on Building a Drupal 8 Module, With a Little AngularJS

Submitted by Matthew on Sun, 03/20/2016 - 13:01

For the moment, I just want to explore some of the features that I found particularly interesting in the module I wrote to show the old Drupal 7 posts in the left sidebar.

First, to access the JSON data that comes through the web service I set up on my Drupal 7 installation at http://webmech.biz, I used the Guzzle HTTP client library, which was added to the initial Drupal 8 release.  The Guzzle API is object-oriented and easy to use:

The Magical (Dis)appearing $this Psuedo-Variable

Submitted by Matthew on Thu, 03/10/2016 - 20:24

At the office, we recently upgraded our staging server to PHP 7.  For the most part, this caused no problems at all and worked very well (and faster!).  But our event pages were failing, just giving us a white screen.  I looked in the "Recent log messages," and saw this:  "Error: Using $this when not in object context."  The code that triggered this error was a non-static class method that was being called statically from within a different class.  In PHP 5, this code only gives a "Deprecated" notice that non-static classes should not be called statically.

Drupal Redirect Paths May Conflict With Existing Directories

Submitted by Matthew on Sun, 12/06/2015 - 21:44

If you are familiar with the Drupal Redirect module, you know it can be a convenient way of creating redirects from URLs that don't really exist.  For example, you can create a redirect for yoursite.com/music to redirect to another website dedicated to your favorite music. 

But what if the URL you want to use as a redirect does already exist?  What if you want yoursite.com/testfolder to redirect to drupal.org?  It won't work--you will get an error message.   If you have already created a folder called testfolder, as in the image below, then your redirect won't work. 

PHP Timeout on Windows/IIS

Submitted by Matthew on Wed, 11/25/2015 - 16:36

This post was written 11/25/2015 and was migrated over from my Drupal 7 site, which is now offline.  Because of that, certain demonstrations in this post may not be functional.

Have you ever run a PHP utility script on a Windows/IIS platform and had it unexpectedly timeout? Your IIS settings for script timeouts might be conflicting with your PHP settings.

Loading Form Definition Include Files in Drupal 7

Submitted by Matthew on Fri, 06/12/2015 - 13:05

This post was written 06/12/2015 and was migrated over from my Drupal 7 site, which is now offline.  Because of that, certain demonstrations in this post may not be functional.

Recently I had to include a form within an existing set of nodes (using hook_node_view), and this form had to make an AJAX callback. I put the form definition and Ajax callback function in a separate file for convenience. From my_ajax_test.module: