Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EvanLovely/8e97c41b23abb6060bf6aecb0ae9d7e3 to your computer and use it in GitHub Desktop.
Save EvanLovely/8e97c41b23abb6060bf6aecb0ae9d7e3 to your computer and use it in GitHub Desktop.
Linking to external resources from the Drupal appearance page

Adding links to Pattern Lab on Drupal Appearance page

Add this to THEME-NAME.info.yml:

resources:
  pattern-lab: /themes/custom/THEME_NAME/pattern-lab/public/
  sassdoc: /themes/custom/THEME_NAME/dest/sassdoc/

Add this code to a custom module:

<?php
/**
 * @file
 * Module code for Pattern Lab.
 */

use \Drupal\Core\Url;

/**
 * Implements hook_system_themes_page_alter().
 */
function MODULE_NAME_system_themes_page_alter($theme_groups)
{
  foreach ($theme_groups['installed'] as $theme) {
    if (isset($theme->info['resources']['pattern-lab'])) {
      $theme->operations[] = [
        'title' => t('Pattern Lab'),
        'url' => Url::fromUri('base:' . $theme->info['resources']['pattern-lab']),
        'attributes' => ['title' => t('Pattern Lab for @theme theme', ['@theme' => $theme->info['name']])],
      ];
    }
    if (isset($theme->info['resources']['sassdoc'])) {
      $theme->operations[] = [
        'title' => t('SassDoc'),
        'url' => Url::fromUri('base:' . $theme->info['resources']['sassdoc']),
        'attributes' => ['title' => t('SassDoc for @theme theme', ['@theme' => $theme->info['name']])],
      ];
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment