Developing:Custom Modules - cu-uis/cu-starterkit-project GitHub Wiki

This documentation isn't as robust as https://github.com/CuBoulder/express_documentation/blob/main/docs/creating_custom_bundles.md, but the goal is the same. Create custom functionality that can stand alone with needing to modify the upstream modules, theme or configuration.

Namespaces

Modules shared on Drupal.org use the project node name to declare namespace. Because these are unique it avoids conflicts when using many projects. For projects that are created for use within CU, we benefit from namespacing those as well.

The recommended pattern is [CODE][SITE/PROJECT][NAME]. For example, custom modules created by UIS specifically for online.cu.edu will be named something like cusys_online_webform_tweaks.

Breaking Modules up into Includes

https://git.drupalcode.org/project/webform/-/blob/6.1.x/webform.module#L29

Include a Views and Configuration Changes in config/install

Adding configuration YAML files to the config/install of a project can be leveraged to include a "sane starting point" for the feature. Any site installing the module can then choose to include those configurations in their project.

Updating a View configuration in config/install.

ddev drush cex -y
mv config/default/views.view.[VIEW NAME].yml web/modules/custom/[MODULE NAME]/config/install/views.view.[VIEW NAME].yml

Managing Twig Templates Outside of the Theme

The easiest way to customize the twig files you'd like to add to a specific site is to first define and development them within the site's theme, but trying to manage a single theme that included all of the Twig files are required for all the site specific customizations would be impossible. These files need to be managed within a custom module specific to that site or the featue.

The example is from the cusys_online_fmp.theme.inc of the Find My Program feature developed for online.cu.edu. The files are added to the templates directory of the module.

 /**
 * Implements hook_theme().
 */
function cusys_online_fmp_theme() {
  return [
    'views_view__cusys_online_fmp_all__page_1' => [
      'base hook' => 'view',
    ],
    'paragraph__cusys_online_fmp_paragraph' => [
      'base hook' => 'paragraph',
    ],
    'views_view__cusys_online_fmp_all__block' => [
      'base hook' => 'view',
    ],
    'views_view__cusys_online_fmp_campus__block' => [
      'base hook' => 'view',
    ],
    "views_view__cusys_online_fmp_degree__block" => [
      'base hook' => 'view',
    ],
  ];
}