• Development

    Increasing Memory for Specific Paths in Drupal 8

    Most of the examples I see for Drupal 8 are for single-path memory limit increases.

    The examples for Drupal 7 often follow the pattern below.

    Here’s a D8 version that supports multiple paths.

    Place this in your settings.php (or site/environment-specific settings.php), then update the paths accordingly.

  • Development

    Conditionally Triggering Salesforce Push Operations in Drupal 8

    The user interface for the Salesforce Suite in Drupal 8 is fantastic. The suite itself is incredibly powerful. Among the many options, for each mapping you create you can specify what operations should trigger a synchronization. Here’s an example:

    We recently faced an issue with the “Drupal entity update” trigger being called too often. The salesforce_push module implements hook_entity_update() , which gets called a lot. After looking at how the functions are called in salesforce_push.module I realized there were two choices:

  • Development

    Patch for Drupal 8.7.14 SA-CORE-2020-004, SA-CORE-2020-005, and SA-CORE-2020-006

    I have a site that’s temporarily stuck on 8.7.14; it’s not worth the risk to update to 8.8.8 right now.

    I was able to diff 8.8.7 and 8.8.8 to figure out what changes were made for these security announcements:

    I could then compare the changes with 8.7.14 to create the patch below, which applies against 8.7.14 without any issues.

    DISCLAIMER: The formal recommendation is to update to 8.8.8 if at all possible. Use the patch below at your own risk.

     

  • Development

    Storing First and Last Name with Social API for Drupal 8

    I recently worked on a project that relied on Social API for Google, Facebook, and Yahoo authentication. Out of the box everything worked great. Our site stores the user’s first name and last name in two fields on the user entity: field_first_name  and field_last_name. There are a few ways to tap into the Social API authentication process (which comes from the Social Auth component).

    Originally we leveraged the SocialAuthEvents::USER_CREATED event in an event subscriber. We set the first name and last name, then re-saved the user. This, however, executes after the user is created. The issue we had was that we also have Salesforce integration and both name fields are required in Salesforce. When the user is first saved it was pushing to Salesforce without the name fields, which triggered an error.

    The solution was to implement a different event handler: SocialAuthEvents::USER_FIELDS

    This lets you manipulate the user fields before the user is saved. I poked through the Social Auth code and figured out how to get the first and last name values. Here’s the working solution:

    web/modules/custom/mymodule/mymodule.services.yml

    web/modules/custom/mymodule/src/EventSubscriber/MymoduleSocialAuthSubscriber.php

    After creating/updating the files above, just clear the caches and test.

  • Development

    Overriding “Required Message” on Composite Fields in Webform (Drupal 8)

    The more commonly used fields in Webform (text, radios, etc.) offer the ability to set a custom Required message string. This is the text that shows in the error message when a required field is not filled.

    Here’s what that screen looks like when you’re configuring a field on the Build screen:

    Required message

    There are several element types that do not provide a UI field to set this Required message value. The composite Name and Advanced Address field are two examples I encountered. For these fields you have to dig a little deeper, but it’s easy once you get the hang of it. Visit the Advanced tab for the field, then scroll to the bottom where you’ll see a Custom Settings fieldset.

  • Development

    Snippet: MySQL table sizes ordered by largest to smallest (in MB and Row Count)

    Show All Tables By Size in MB

     

    Show All Tables By Size in MB (if > 1 MB)

     

    Show All Tables By Number of Rows

     

  • Development

    Using Drupal 8 Persistent Login Module on Platform.sh

    The Persistent Login module relies an extra cookie to maintain a Drupal user’s session. The configuration screen for this module lets you specify a prefix for the cookie. The default is “PL”. If you are using the site on HTTPS, the module prepends an “S” to the cookie it creates. Here’s an example cookie name: SPLfa0650d6d985433d455a3b15cc70fd9b .
    Platform.sh lets you configure cookie cache settings via routes.yaml .
    If you’re using Persistent Login you must tell the system not to ignore this cookie.
    Here’s a standard (and simple) routes.yaml  file on a Drupal 8 site:
    Here’s a modified version which allows Persistent Login to work correctly:

     

    There is a bit more discussion around how these cookies are handled here: https://www.drupal.org/node/2898065/discuss

  • Development,  Tech Tips

    Switch Audio Input/Output Device using Alfred

    My top two must-have Mac apps are Keyboard Maestro and Alfred. If you know me, you’ve likely heard me say this, ad nauseum. I use these two apps countless times each day. Often I use them to run command line scripts via hotkey. This is one such implementation.

    Recently I picked up a Jabra Evolve 65 headset. I keep it connected to my Mac via USB. Also, I have some speakers hooked up via the external speaker jack. You can only send output to one of these devices at a time (speakers OR headset). I desired a way to quick-switch between the two. I chose to use Alfred for this.

    The steps below show how to create some quick switchers like this:

    Alfred sound switchers

    Switch to speakers

    Requirements and Initial Setup

  • Development

    Overriding a Webform Confirmation Message in Drupal 8

    There are a few reasons you may need to override a webform confirmation:

    • Out of the box webform doesn’t allow you to add some tags (e.g., <button>) to a webform confirmation message. When you save it strips them out.
    • What if you needed to alter the webform message based on the values submitted in the webform?
    • What if you needed to alter the webform message based on where the user saw the webform?
    • etc…

    Thankfully, you can use a standard preprocess hook to override the confirmation output.

    In this particular example I needed to override the output of the message to include a button tag. I needed this to only happen if specific GET params had specific values.

    First, I modified the confirmation message settings as shown here: