You are here

simple_styleguide.module in Simple Style Guide 8

File

simple_styleguide.module
View source
<?php

/**
 * @file
 * Contains simple_styleguide.module.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function simple_styleguide_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the simple_styleguide module.
    case 'help.page.simple_styleguide':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('TODO') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_theme().
 */
function simple_styleguide_theme() {
  return [
    'simple_styleguide' => [
      'render element' => 'children',
      'variables' => [
        'default_patterns' => NULL,
        'default_colors' => NULL,
        'custom_patterns' => NULL,
        'form' => NULL,
      ],
    ],
    'simple_styleguide_pattern' => [
      'variables' => [
        'pattern_id' => NULL,
        'pattern' => NULL,
      ],
    ],
  ];
}

/**
 * Implements hook_theme_suggestions_HOOK().
 */
function simple_styleguide_theme_suggestions_simple_styleguide_pattern(array $variables) {
  $pattern_id = $variables['pattern_id'];
  return [
    'simple_styleguide_pattern__' . $pattern_id,
  ];
}

/**
 * Implements hook_page_attachments_alter().
 *
 * Prevent styleguide from being indexed even though permissions alone should
 * prevent this from happening.
 */
function simple_styleguide_page_attachments_alter(array &$attachments) {
  $route_name = \Drupal::routeMatch()
    ->getRouteName();
  if (in_array($route_name, [
    'simple_styleguide.controller',
  ])) {

    // Set meta tag for robots.
    $robots = [
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => [
        'name' => 'robots',
        'content' => 'noindex, nofollow',
      ],
    ];
    $attachments['#attached']['html_head'][] = [
      $robots,
      'robots',
    ];
  }
}