• Development

    Quick Tips for a Drupal 7 to Drupal 8 Migration

    Here are a few quick tips for a Drupal 7 to Drupal 8 migration. I will add more over time; admittedly it’s pretty lame right now!

    For general Drupal 8 Migrate API tips, you may also want to check out my other post: Drupal 8 Migrate – Tips and Tricks

    Source Plugins

    If you’re using a source plugin like d7_user or d7_node it will help you understand what’s happening if you view the source code for the plugin. Pay close attention to the query(), prepareRow(), and fields() methods.

  • Development

    Only Migrating Published Nodes in a D7 to D8 Migration

    I’m not going into much detail here but hopefully this helps someone.

    If you need to migrate only published nodes you can extend the d7_node plugin and add a condition to the query.

    First, create a file in your module like /modules/custom/mysite_migrate/src/Plugin/migrate/source/MysiteNewsNode.php that extends the d7_node plugin:

  • Development

    Using GROUP_CONCAT to Combine Rows in a Drupal Query

    Recently I was working on a D7 to D8 migration. I was trying to import news items and their taxonomy terms (among many other things). To make things simple I wanted the query results to have (for each node) a single field that contained a comma-separated list of taxonomy terms which I could then explode during the row processing. Using GROUP_CONCAT we can achieve this! Let’s break it down:

    The Drupal 7 site has the following structure (focusing on the important bits for this blog post):

    The migration relies on the d7_node migrate source plugin, which basically queries for nodes of a specific type. The query object looks like this (simplified for this blog post):

  • Development

    User-chosen Field Output Styles in 5 minutes using Display Suite

    I’m working on a site that has a “Statistics” paragraph bundle. The output looks like this:

    The specification calls for the content author to be able to choose between a few different visual styles for the header (title), shown as Statistics: 3 Up Feature Ipsum Sit H2 in the screenshot above.

    The simplest way to achieve this is to add a field to the paragraph bundle:

    Note that the key (key|value) needs to work as a css class.

  • Development

    Adding Fields to Inline Entity Form Table

    Inline Entity Form is a useful module for reference entities and being able to edit them in place.

    Here’s what the edit form looks like out of the box for an unlimited value entity reference:

    Default output

    Often it’s helpful to provide additional information to your editors.

    If you have a look at inline_entity_form.module you will find a function called theme_inline_entity_form_entity_table(). Within this you will see how this table is built, and how you can manipulate the form to add additional columns of information.

  • Development

    Using the Messenger Service Instead of drupal_set_message in Drupal 8

    As you may know, drupal_set_message()  is deprecated in Drupal 8.5.0.

    Here’s a quick example of using dependency injection to use the new Messenger service:

    mymodule.services.yml

    src/MymoduleAuthentication.php

     

  • Development,  Tech Tips

    Automatically Put Files Into a YYYY/MM Directory Structure

     

  • Development,  Tech Tips

    Using PHPStorm for Git Diff and Merge tools (Mac)

    You love git-difftool, right? Of course! You also love PHP Storm, right? Of course! This easy procedure lets you use PHP Storm as your git-difftool.

    1. Open a project in PHP Storm
    2. Click Tools » Create Command-line Launcher…
    3. Edit your ~/.gitconfig file:
    4. Open the project in PHP Storm (see notes below)
    5. Open iTerm2 (or any other terminal emulator)
    6. Use git difftool as you normally would (e.g., git difftool .htaccess)

    Observations

    1. If you don’t have PHPStorm open when you try to use git difftool it doesn’t seem to work. I need to see if I can get it to open non PHP Storm projects, and/or I need to figure out how to switch on-the-fly between vimdiff and PHP Storm as my difftool.
    2. If you have PHP Storm open but the project itself isn’t open, “Annotate” is not available on right-click. Other functionality may be missing too. If you project is already open in PHP Storm you can annotate the diff!

    Thank you to JohnAlbin for the configuration snippet above.

  • Development,  Tech Tips

    Find and Open (in vim) Multiple Files

    This is a quick set of examples for finding and opening multiple files in Vim.

     

  • Development

    Basic HTTP Authentication in Drupal Site Using settings.php

    Here’s a quick and painless way of preventing public access to a Drupal site using settings.php (or settings.local.php).

    I’ve been using this for development and staging sites that I want to keep private.

    If you want this to be available to all settings*.php files you should put this near the top of your settings.php file:

    Then, you can leverage it wherever you’d like. For example, on an Acquia site I might add this to the bottom of settings.php:

    For non-Acquia sites I’d call the function at the bottom of settings.local.php.