charts-8.x-4.x-dev/charts.module
charts.module
<?php
/**
* @file
* Charts - Module.
*/
use Drupal\Core\Hook\Attribute\LegacyHook;
use Drupal\views\ViewExecutable;
/**
* Implements hook_theme().
*
* @phpstan-ignore-next-line
*/
#[LegacyHook]
function charts_theme($existing, $type, $theme, $path) {
return \Drupal::service('charts.hooks')->theme();
}
/**
* Implements hook_preprocess_HOOK().
*/
function template_preprocess_charts_chart(&$variables) {
$element = $variables['element'];
$attributes = $element['#attributes'];
$attributes['id'] = $element['#id'];
$attributes['class'][] = 'chart';
$variables['content'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => $attributes,
'#value' => $element['#chart'] ?? '',
];
$variables['content_prefix'] = $element['#content_prefix'];
$variables['content_suffix'] = $element['#content_suffix'];
$config = \Drupal::config('charts.settings');
$variables['debug'] = [];
if (!empty($config->get('advanced.debug'))) {
$variables['debug'] = [
'#type' => 'details',
'#title' => t('Chart JSON'),
'#open' => FALSE,
'#attributes' => [
'data-charts-debug-container' => TRUE,
],
'#collapsible' => TRUE,
'json' => [
'#prefix' => '<pre class="language-json">',
'#type' => 'html_tag',
'#tag' => 'code',
'#attributes' => [
'class' => ['language-json'],
],
'#value' => t('If this is blank, your library will need to implement code in your JavaScript. Please see the README.md.'),
'#suffix' => '</pre>',
],
];
}
}
/**
* Implements hook_views_data().
*
* @phpstan-ignore-next-line
*/
#[LegacyHook]
function charts_views_data() {
return \Drupal::service('charts.hooks')->viewsData();
}
/**
* Implements hook_views_pre_view().
*
* @phpstan-ignore-next-line
*/
#[LegacyHook]
function charts_views_pre_view(ViewExecutable $view, string $display_id, array &$args): void {
\Drupal::service('charts.hooks')->viewsPreView($view, $display_id, $args);
}
/**
* Implements hook_library_info_alter().
*
* @phpstan-ignore-next-line
*/
#[LegacyHook]
function charts_library_info_alter(array &$libraries, string $extension) {
\Drupal::service('charts.hooks')->libraryInfoAlter($libraries, $extension);
}
