Tideways and Xhgui using Lando

While I prefer using Valet+ for my Drupal development, I have been asked a few times to share my Lando + Tideways setup. I can’t go into too many details at this point, because it’s been a while since I’ve used this, but here’s my setup. I’ve included some documentation within some of the files (especially at the bottom of .lando.yml).

You can see some explanation and screenshots of Tideways and Xhgui in my Tideways and Xhgui using Dev Desktop post if you need a bit of an introduction. Also, you may be interested in seeing how I got Tideways running with Valet+.

This example is for Drupal 7. You can rework it easily to work with Drupal 8. The .conf may not be required in either case. Read more ›

Tagged with: , , ,
Posted in Development

Twig Caching Issues in Acquia Cloud Enterprise

I’ve recently run into an issue where my site (on Acquia Cloud Enterprise) has node displays that were flip-flopping between an older version of a Twig template file, and the most recent version. I tried all combinations of drush cr, varnish cache clearing, and clearing the cache through the Drupal UI.

After reading through No reliable method exists for clearing the Twig cache, I landed on this page at Acquia: https://support.acquia.com/hc/en-us/articles/360005167754-Drupal-8-Twig-cache

I SSH’d into the production server I always SSH into, and I ran the command as shown. I did this repeatedly. I did a drush cr after. I did a drush cr before. Nothing was working. My pages were showing up with the old template, or the new template, and it seemed to be at random.

Ultimately I re-read the documentation page, more thoroughly this time, and discovered this: “connect to each web server instance and run a command like this…

Ahah! EACH web server.

So, I logged into the Acquia Cloud interface, found the other production server’s connection string (myuser@someserver.prod.hosting.acquia.com), connected, and ran the same command. After another drush cr all of the pages were using the new template.

That’ll teach me to jump straight to executing commands without reading the instructions carefully.

Tagged with: , , ,
Posted in Uncategorized

Migrating Into Existing Nodes in Drupal 8, Including Rollback Missing from Source

Please read this entire post (including the disclaimer at the bottom) before you put any of it to use.

The site I’m basing this off had an existing set of nodes and a new migration that had the same nodes (and many more) in the data source. I wanted to map the existing nodes to their migration-based counterparts and treat every node as if it originated from the migration.

As of today, using a few patches makes it easy (thanks contributors!) to rollback items that no longer exist in a D8 migration’s source data. See Migrate support for deleting items no longer in the incoming data and Implement rollback of items no longer in source data

With these patches you can import and rollback in two commands:

What if the data that you’re migrating (and rolling back if removed) already existed in Drupal before you started using the migration? If you attempt to migrate content, then rollback removed items, you will find that the items that no longer exist in the source will not be deleted if they existed before the migration.

First, I should describe how I’m pulling data into existing nodes.

This is as simple as populating the node ID in the process section of your migration YML, like this:

Read more ›

Tagged with: , ,
Posted in Development

Combining Steps in Behat for Drupal

Lately I have found myself repeating several lines of behat steps over and over again. Here is a sample of the behat code I use to choose a specific checkbox from an entity browser popup:

There are a few steps in here that are custom, but explaining them would be beyond the scope of this post; just assume they do what they describe (switching focus to an iframe, and clicking a checkbox).

The issue I was having is that every time I wanted to do that one action (pick an image from an entity browser) I was repeating all 8 lines of code.

I began looking for ways of making this set of steps repeatable. After some failed attempts at extending MinkContext and MinkAwareContext I came across scenario hooks via this StackOverflow post. I discovered the @BeforeScenario, which is executed before every scenario in each feature (where it’s used). Using this hook to access contexts from other contexts was documented on behat.org but required a few tweaks for the Drupal implementation. Here is what I ended up doing (based on the default FeatureContext.php you get when you install behat for the project: Read more ›

Tagged with: ,
Posted in Development

Adding Level Number Class to Menu Items in Drupal 8

This is a quick post showing how to add level classes to menu items in Drupal 8.

Here’s the result, showing the additional menu--level-N  and menu-item--level-N  classes:


Step 1: Create a New Twig template File

Determine which Twig template you need to override. I recommend reading the official docs on this. In my case, for a menu called infofor, I copied docroot/core/themes/classy/templates/navigation/menu.html.twig to docroot/themes/custom/mytheme/templates/navigation/menu--infofor.html.twig .

Step 2: Update the Twig Code Read more ›

Tagged with: , ,
Posted in Development

Setting Drupal 8 Node Properties with Behat

The title of this post could also have been “Opening and Closing a Details Element with Behat” or “Clicking Any Element with Behat”.

The Drupal 8 node add/edit screen has a number properties on the right side of the screen. I wanted to use Behat to click the “Provide a menu link” checkbox. On page load this MENU SETTINGS pane is closed like the others.

Here’s an example:

Node add/edit

The “URL SETTINGS”, “MENU SETTINGS”, actually mask a <details>  element.

The “MENU SETTINGS” markup looks like this:

Menu settings markup

I expected to be able to write a few lines of Behat like this:

Unfortunately this results in the failure: element not interactable.

So, I thought I may need to first click to open the MENU SETTINGS pane so that I can see the checkbox before I try to click it. I modified my code to look like this:

Unfortunately this results in the failure: Link with id|title|alt|text “Menu settings” not found.

I tried using the edit-menu  id, “MENU SETTINGS” in all caps, etc. but it always resulted in the same “Link with …”

I realized the click step is only looking for links.


I added a new step definition to my features/bootstrap/FeatureContext.php file:

I updated my Behat code and found success!

Tagged with: , ,
Posted in Development

Hiding Country from an Address Field’s Output in Drupal 8

There are two field formatters available on an Address field in Drupal 8:

The Plain formatter uses a Twig template file but it would take some work to override with the proper markup. The Default formatter doesn’t use a Twig template file so you cannot simply override via Twig.

If your goal is to simply hide the country value from the output you can use hook_preprocess_field to alter the country value. As it turns out, unsetting the country field doesn’t help, but setting the value to an empty string does work.

Here’s an example (in a module; you can put in your .theme file if you’d prefer the setting to be at the theme level).


Tagged with: , ,
Posted in Development

Tideways and Xhgui in Valet+ (Valet Plus)

This post is for folks who are already familiar with PHP, command line, Valet, Tideways and XHGui.

You can see some explanation and screenshots of Tideways and Xhgui in my Tideways and Xhgui using Dev Desktop post if you need a bit of an introduction.

I’ve successfully gotten Tideways running with Acquia Dev Desktop, Lando, and now Valet+. This post illustrates the process I used to get Tideways, Xhgui, and their dependencies running on my Mac for use in Valet+ sites. Read more ›

Tagged with: , , , ,
Posted in Development

Access Entity Properties in a Field Twig Template

This doesn’t need much of an explanation. You can use any entity methods as far as I can tell.

Here’s an example showing how to get the node ID in a field template:


Tagged with: ,
Posted in Development

Modifying Rows During a Drupal 8 CSV Migration

Migrate Source CSV is currently the source plugin of choice for doing a CSV-to-Drupal migration with the Migrate API in Drupal 8. In this post I will demonstrate how to manipulate the CSV data in realtime during the migrate:import operation. You can think of this as the equivalent to prepareRow() that you have seen elsewhere, like my blog post Extending the Migrate Plus JSON Parser in Drupal 8.

Please make sure you have a working migration before you begin; it’ll make things easier to troubleshoot if you know you had a good starting point. Read more ›

Tagged with: , , , ,
Posted in Development