drupal

recent posts related to the drupal content management system

Disabling Drupal 8 page caching significantly increases CPU use

As I noted five days ago, Mollom went out of business so I had to switch this Drupal 8 website to use a different module to control comment spam. I ended up adding two modules that work together, but the side effect of using their best features is that they end up disabling Drupal 8 page caching. This image clearly shows the result that disabling page caching has on CPU use.

Mollom is out of business

On April 3, 2018 this website suddenly got a ton of spam comments. Fortunately I caught the probably very quickly, and turned off the ability for people to post comments here. When I checked into the problem I found that Mollom — created by the same person who created Drupal — basically went out of business on April 2nd. (I’m sure there was some warning about this decision, but I sure didn’t get it.)

I’m often surprised when people who offer a free service shut down that service without asking a simple question: “Would you be willing to pay for this service, and if so, how much?”

(I’ll re-enable the ability to post comments here when I find a good replacement for Mollom.)

A Drush 9 list of commands (for Drupal 8)

I’m sure there’s something I’m missing here, but ... as I’m just getting started using Drush 9 to manage a Drupal 8 website, I can’t find a list of Drush 9 commands on the drush.org website. Therefore, in an effort to make my life easier (and hopefully yours), here’s a list of Drush 9 commands.

How to write if/then/elseif/else in Drupal 8 Twig templates

As a quick note Drupal programming note, here’s an example of how to write if/then/elseif/else in Drupal 8 Twig templates:

{% if node.getType == 'photo' %}
...
{% elseif node.getType in ['book', 'page'] %}
...
{% else %}
...
{% endif %}

While I’m in the neighborhood, here are a few more if conditions I’ve written recently:

How to write “If string starts with” in Drupal 8 Twig templates alvin July 30, 2017 - 11:53am

If you ever need to write a “string starts with” comparison in Drupal 8 Twig templates, I just used this approach in a node.html.twig template file and I can confirm that it works:

{% if uri starts with '/foo' %}

More accurately, what I did was to first get the URI for the current Drupal node, and then I perform that test:

How to get the URI of the current node in a Drupal 8 Twig template theme file

As a quick note, I was just able to get the URI of the current page (node) in a Drupal 8 Twig template theme file using this code:

{% set uri = path('entity.node.canonical', {'node': node.id}) %}

As an example, I’m rendering some different content based on the URI of the current node, so I first use that code to set the uri field, then I have a little Twig if/then/else condition like this:

{% if uri starts with '/foo' %}
    <div>Option Foo here ...</div>
{% elseif uri starts with '/bar' %}
    <div>Option Bar here ...</div>
{% else %}
    <div>Option Baz here ...</div>
{% endif %}

In summary, if you wanted to see how to get the URI of the current page/node when using a Drupal 8 Twig theme template file, I hope this example is helpful.