Skip to content

Instantly share code, notes, and snippets.

View nJim's full-sized avatar

Jim Vomero nJim

View GitHub Profile
@nJim
nJim / 1. README.md
Last active June 22, 2018 07:24
Work Sample: Drupal Data Migration

Brewery Import Module

Migrating data from an external JSON feed into a Drupal 8 website.

Drupal’s migration initiative has a slew of tools to fetch and process data. This includes the ability to map content types between major versions of the application. These tools are currently in beta and are overkill for my project. Instead, this gist include part of a ‘brewery_import’ module that created data in a new Drupal 8 site from an external JSON feed.

Things I like in the Gist

  • Highlights the importance of interfaces. New features in PHP7 allow developers to type-hint the parameters and return values of each method – guaranteeing appropriate methods are available to complete these import tasks.
  • Designed with testing in mind. Most methods are short, contain a single purpose, and separate from database and external influencers. Dependency injection allows services to be loaded as needed at runtime.
  • View the complete repository on Github at
@nJim
nJim / 1. README.md
Last active June 22, 2018 15:54
Work Sample: Custom Entity Abstract

Custom Entity Tools Module

Boilerplate, scripts, and supporting files to generate custom entities

Nodes are feature-rich but are not always the best fit for storing data in Drupal. I created this module to store all of the base definitions, interfaces, and scripts needed to define a simple entity that fits my needs.

Things I like in the Gist

  • Role of Object Inheritance. Drupal provides many different interfaces for building entities. Extending these to create my abstract classes ensure that my module will grow with the application.
  • Easy to Upgrade. This module includes many interfaces to govern the custom entity definitions. Some interfaces are even empty to act as future placeholders for work. This has made it easy to change my custom entities when needed. For example, the addition of EditorialContentEntityBase in Drupal 8.4.
  • View the complete repository with many more files on Github at ` https://github.com/nJim/custom_entity_t
@nJim
nJim / 1. README.md
Last active June 22, 2018 07:23
Work Sample: Geocoder and Custom Action

Geocoder Module

Generate waypoints from address values via Google Geocoder API.

Several of my websites include Google Maps. The points on the map are derived from address fields using a Google API. The geocoding task can take place on entity-save, as a custom action, or at runtime.

Things I like in the Gist

  • Standard Data Types. There are many ways to represent an addresses, especially when considering internationalization. This module uses the Drupal Commerce Address interface to set a contract for predictable storage. The Geofield modules WktGeneratorInterface enforces a standard return.
  • Logging. This module includes the Drupal Logger and Messenger to communicate information about geocoding process. These should be part of every module for catching and reporting errors.
  • View this code a part of the Brewery Website on Github at https://github.com/nJim/beer.jimvomero.com/.
@nJim
nJim / README.md
Created June 22, 2018 05:45
Work Sample: Drupal 7 Custom Form Validation

Form Validation

Custom Form Validation for Drupal 7

This is from a D7 custom formbuilder module that contains abstracts and helper functions to build FAPI forms. These files include the server-side and client-side logic that handles and throws validation errors.

Things I like in the Gist

  • Extension of Drupal JS Object. The client side validation checks form input on element blur and clear errors on keyup. This logic is attached to the Drupal.ajax object and runs for each stage of form build and rebuild.
  • Standard Element Settings. Drupal allows developers to pass custom #keys that are not currently reserved by the Form API. These elements are pulled from the form for server side validation and passed through the Drupal.settings object for client side validation.
@nJim
nJim / 1. README.md
Last active June 22, 2018 07:11
Work Sample: Fun with CSS and JavsScript

Stranger Things Easter Egg

Added creepy effect to the website as part of a marketing campaign.

This easter egg was added to our website before the release of season 2 of the TV show Stranger Things. The website effects are nods to the show and intended to be a fun and sharable feature.

Things I like in the Gist

  • Coding for Fun. Working at a large institution, it is rare that my professional projects can be this fun. I had a lot of freedom in what I added to the design and enjoyed experimenting with newer CSS effects.
  • Word was spread on social media and a few folks mentioned our work online. You can still see a video of the effect at Stranger Things Effect Link
@nJim
nJim / notes.md
Created October 13, 2022 17:53 — forked from jhedstrom/notes.md
PHPUnit based tests in Drupal 8

Local setup

  • Environment variables:

    export SIMPLETEST_DB=mysql://user:pass@localhost/db_name
    export SIMPLETEST_BASE_URL=http://d8.dev
    
  • or copy core/phpunit.xml.dist to core/phpunit.xml and edit accordingly