You are here

draggable_dashboard.module in Draggable dashboard 8.2

Same filename and directory in other branches
  1. 8 draggable_dashboard.module

File

draggable_dashboard.module
View source
<?php

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

/**
 * Implements hook_help().
 *
 * @inheritdoc
 */
function draggable_dashboard_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.draggable_dashboard':
      $text = file_get_contents(dirname(__FILE__) . "/README.md");
      if (!\Drupal::moduleHandler()
        ->moduleExists('markdown')) {
        return '<pre>' . $text . '</pre>';
      }
      else {

        // Use the Markdown filter to render the README.
        $filter_manager = \Drupal::service('plugin.manager.filter');
        $settings = \Drupal::configFactory()
          ->get('markdown.settings')
          ->getRawData();
        $config = [
          'settings' => $settings,
        ];
        $filter = $filter_manager
          ->createInstance('markdown', $config);
        return $filter
          ->process($text, 'en');
      }
  }
  return NULL;
}

/**
 * Implements hook_theme().
 */
function draggable_dashboard_theme($existing, $type, $theme, $path) {
  return [
    'draggable_dashboard_block' => [
      'variables' => [
        'attributes' => [],
        'columns' => [],
        'dashboard' => [],
      ],
      'template' => 'draggable-dashboard-view',
    ],
    'block__dashboard_item' => [
      'template' => 'block--dashboard-item',
      'base hook' => 'block',
    ],
  ];
}

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function draggable_dashboard_theme_suggestions_block_alter(array &$suggestions, array $variables) {
  if (isset($variables["elements"]["#draggable_dashboard"]) && $variables["elements"]["#draggable_dashboard"]) {
    $current = $suggestions;
    $suggestions[] = 'block__dashboard_item';
    foreach ($current as $theme_hook) {
      $suggestions[] = preg_replace('/^block/', 'block__dashboard_item', $theme_hook);
    }
  }
}