• 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.