Skip to content

Instantly share code, notes, and snippets.

@grayside
Last active April 12, 2017 05:43
Show Gist options
  • Save grayside/1f32cd3a3003067d5a7d5b47af048fae to your computer and use it in GitHub Desktop.
Save grayside/1f32cd3a3003067d5a7d5b47af048fae to your computer and use it in GitHub Desktop.
Linking to external resources from the Drupal appearance page

For the sake of this example, do the following:

  1. Add this to your theme.info.yml. There are alter hooks that can change this, and for that matter, we could just set these to true and load the paths some other way.
resources:
  pattern-lab: /themes/custom/phase2/pattern-lab/public/
  sassdoc: /themes/custom/phase2/dest/sassdoc/
  1. Add some module code like so:
<?php
/**
 * @file
 * Module code for the Now You See Me module.
 */

use \Drupal\Core\Url;

/**
 * Implements hook_system_themes_page_alter().
 */
function phase2_views_idea_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']])],
      ];
    }
  }
  1. See Screenshot.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment