October 2015

How to make custom Guzzle requests in Drupal 8 modules

If you're sending a request to a custom URL in Drupal 8, you might be tempted to implement a solution using cURL or another library. However, Drupal core comes with Guzzle, a "PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services." As with most things in Drupal, it's not obvious how to use something immediately, so here's a demo to show you how to take care of sending a request to an arbitrary URL inside a custom Drupal module. You might use this example class to display a status code on some page.

How to check a user role inside a custom module in Drupal 8

If you need to check for a specific role such as 'administrator' in Drupal 8, the process is changed from past versions. The following is an example of how you'd check for an administrator role when rendering the user edit form. You might do this if you were unsetting form variables based on role:

Drupal 8 Site Building Gotcha: System Blocks

For those starting to build on Drupal 8, some things can be in the same place as Drupal 7 while others can be "hidden". While the idea is to move things to more logical places, sometimes it's confusing to site builders since they have to learn the system anew in some regards.