User login

Drupal

Why are twig template comparisons such annoying strings?

A boolean field told in display settings to show as zero or one is actually rendered like this:

" 0 "
" 1 "

That is, a string of the number with a space on either side. Why?

That is from testing using {% set lightbox_class = content.field_lightbox|render %}

At least this works:

{% set lightbox_class = content.field_lightbox|render|trim == 1 ? ' lightbox' %}

So does:

{% set lightbox_class = content.field_lightbox|render|trim ? ' lightbox' %}

Implementing Webmentions for Drupal 8

Starting informational links:

Drush update not seeing the patch-level version of Drupal 8?

Does it appear that Drush update is not fetching the newest minor version update of Drupal 8? Changelog says 8.0.0 at the top, but you know 8.0.2 has been released, and drush up or drush upc says update information last refreshed that day yet says "No code updates available."?

Set a separate browser window page title from HTML page title (Drupal 7)

This code shows how to set the browser bar page title the Page Title module way, without that module. (This was motivated simply because we were already gathering the info for another purpose in hook_node_view_alter(); there's no reason not to use Page Title!)

Setting breadcrumbs to exactly what you want

In Drupal it is quite easy to set breadcrumbs with the function drupal_set_breadcrumb(), which takes an array of links (as you would make with the l() function). It's a bit of a blunt instrument but it works (and wins out over hook_menu_breadcrumb_alter()).

Drupal in a virtual machine cheat sheet

This cheatsheet presumes you're already set up with VirtualBox and Vagrant, configured for Drupal. (Agaric has our own base box to have a head start on setting up for this purpose, but some of the magic is in the Vagrantfile stored with our projects.)

In a terminal, go to the directory holding your Vagrantfile and your project code. Then the fun begins.

vagrant up

to start the virtual machine.

Add a replacement pattern token for a Views field rewrite results

Views fields offer the opportunity to "Rewrite results: Rewrite the output of this field". The option further specifies "Enable to override the output of this field with custom text or replacement tokens." It then provides a textarea with the instruction: "The text to display for this field. You may include HTML. You may enter data from this view as per the 'Replacement patterns' below." The replacement patterns, in turn, have the introduction: "The following tokens are available for this field.

Passing a group object deprecated, pass through the arguments array instead

You've upgraded migrate module from 7.x-2.5-rc2 or such to 7.x-2.6. Your migrations may run, or not run, with this complaining error: "Passing a group object to a migration constructor is now deprecated pass through the arguments array passed to the leaf class instead."

Replace this:

How to programmatically rename a content type (change node type machine name)

Set old_type if you want to programmatically update a node type / machine name.

(This is not about changing the type of a node, but changing what type is called on the machine-info level.)

$type->old_type is what node_type_save() checks for when updating a node type, if it's not set it will create a new node type even if orig_type is set to an existing bundle. So really all you need to do right before saving a modified content type is set the old_type to the orig_type, such as:

Configure Memcache on a Drupal site

This has to be done for each site. This is after installing Memcache on your server.

Memcache module

Then, in settings.php, add:

Syndicate content