Creating reusable functionality across projects

How many times have you built...

  • Three Column Component
  • Text and Image Component
  • Slideshow Component
  • Simple Text Component

How many times have you built it just a little bit different???

Cat Gif

Bootstrap Paragraphs Module

The Bootstrap Paragraphs module provides a suite of content and layout Paragraph bundles made with the Bootstrap front-end framework.

Building a better page builder

Boostrap Paragraphs Demo

Strategy

  • Create a module that would make the basic paragraphs needed for every site.
  • Create base templates & CSS that could be used with any theme that includes Bootstrap.
  • Harness the power of Entity Reference Revisions fields to nest Paragraphs.
  • Have global width & background color options.

Content bundles

Common semantically organized fields, and reference fields to common entities.

  • Simple HTML
  • Image
  • Blank
  • Drupal Blocks
  • Views
  • Contact Forms/Webforms are Submodules

Layout bundles

Entity Reference Revisions fields to other Paragraphs.

  • Columns
  • Carousel
  • Accordion
  • Modal
  • Tabs

Building a module from config

Building a module from config

  • Create functionality in a blank Drupal install
  • Create module structure
  • Add Templates, CSS, and JS
  • Add Function to override Template
  • Export Config, delete UUIDs, Name space/change file names

Create functionality in a blank Drupal install

Spin up a sandbox on your favorite hosting platform or on your local dev environment and build your functionality.

Create module structure

Bootstrap Pages Module Structure

Add Templates, CSS, and JS

  • Add any templates you need.
  • Add a CSS file.
  • Add a JS file if needed.
  • Configure them in the module's .libraries file.

Export Config, delete UUIDs, Name space/change file names

Bootstrap Pages Config Example

If needed, add function to override Template in .module

Bootstrap Pages Module Hook Theme

Bootstrap Pages

Install, Test, & Share the finished product

Bootstrap Pages

Bootstrap Pages

  • Content Types
    Article, Author, Landing Page
    Includes Bootstrap Paragraphs, Meta tags and Schema.org markup; optimized, responsive images, preconfigured friendly URLs; and an organized administration
  • Taxonomies
    Category, Topic, Type
  • Views
    All Articles, Articles by Terms

SEO Starter

Config only module that had module dependencies and starter config for Search Engine Optimization.

SEO Starter


function seo_starter_override_config($config_name, $path) {
  $active_storage = \Drupal::service('config.storage');
  $active_storage->write($config_name, Yaml::parse(file_get_contents($path . '/config/override/' . $config_name . '.yml')));
}

/**
 * Implements hook_install().
 */
function seo_starter_install() {
  // Set path.
  $path = drupal_get_path('module', 'seo_starter');
  // Override configs.
  seo_starter_override_config('coffee.configuration', $path);
  seo_starter_override_config('easy_breadcrumb.settings', $path);
  seo_starter_override_config('google_analytics.settings', $path);
  seo_starter_override_config('metatag.metatag_defaults.403', $path);
  seo_starter_override_config('metatag.metatag_defaults.404', $path);
  seo_starter_override_config('metatag.metatag_defaults.front', $path);
  seo_starter_override_config('metatag.metatag_defaults.global', $path);
  seo_starter_override_config('metatag.metatag_defaults.node', $path);
  seo_starter_override_config('metatag.metatag_defaults.taxonomy_term', $path);
  seo_starter_override_config('metatag.metatag_defaults.user', $path);
  seo_starter_override_config('pathauto.pattern.content', $path);
  seo_starter_override_config('pathauto.pattern.taxonomy', $path);
  seo_starter_override_config('pathauto.pattern.user', $path);
  seo_starter_override_config('pathauto.settings', $path);
  seo_starter_override_config('redirect.settings', $path);
  seo_starter_override_config('simple_sitemap.custom', $path);
  seo_starter_override_config('simple_sitemap.settings', $path);
}
          

Media Entity Browser

Drupal Media Entity Browser module page

Free like a Puppy

Puppy yawning
  • Config is now yours. Only an update hook will update.
  • Templates/Libraries can be overriden by the theme.
  • Can even uninstall the module for complete break.
Drupal logo

All have their pluses and minuses, but all have issues when you want to customize them

Lightning Thunder Open Social
OpenChurch Varbase

Benefits

"given enough eyeballs, all bugs are shallow"

Linus's Law - Eric S. Raymond in his essay and book The Cathedral and the Bazaar (1999)

What about WordPress?

WordPress Plugin using ACF and Post Meta and WP-CFM Oh my! Or Gutenberg blocks or...

What about DevOps?

  • Composer Starters
  • CircleCI Starters
  • Theme Starters

Foundation Paragraphs and Foundation Pages

Help me plan and build!

Foundation Paragraphs and Foundation Pages Drupal modules

The End

Continuing the conversation: