utilikit-1.0.0/modules/utilikit_playground/utilikit_playground.module
modules/utilikit_playground/utilikit_playground.module
<?php
/**
* @file
* UtiliKit Playground module - Interactive utility class testing environment.
*
* Provides a dedicated playground interface for testing and experimenting
* with UtiliKit utility classes. Includes live preview capabilities,
* interactive examples, and development-focused features for rapid
* prototyping and learning.
*/
declare(strict_types=1);
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*
* Provides contextual help throughout the Drupal admin interface.
*/
function utilikit_playground_help(string $route_name, RouteMatchInterface $route_match): ?string {
if ($route_name === 'help.page.playground_help') {
return _utilikit_helper_render_readme();
}
return NULL;
}
/**
* Implements hook_theme().
*
* Defines theme templates for the UtiliKit Playground interface.
* Registers the main playground template with render element support
* for flexible content rendering.
* An array of theme hook definitions with template configurations.
*/
function utilikit_playground_theme($existing, $type, $theme, $path): array {
return [
'utilikit_playground' => [
'render element' => 'elements',
'template' => 'utilikit-playground',
],
];
}
/**
* Implements hook_page_attachments().
*
* Attaches UtiliKit libraries and configuration to playground pages.
* Forces inline rendering mode for immediate visual feedback and
* configures development-friendly settings for the playground
* environment.
* The page attachments array to modify. Passed by reference to allow
* direct modification of libraries, settings, and other attachments.
*/
function utilikit_playground_page_attachments(array &$attachments): void {
$route_name = \Drupal::routeMatch()->getRouteName();
// Only attach on playground pages.
if ($route_name !== 'utilikit_playground.page') {
return;
}
// Get main module settings for dev mode, transitions, etc.
$config = \Drupal::config('utilikit.settings');
// Force inline mode for playground.
$attachments['#attached']['drupalSettings']['utilikit'] = [
'devMode' => (bool) $config->get('dev_mode'),
'showPageErrors' => (bool) $config->get('show_page_errors'),
'enableTransitions' => (bool) $config->get('enable_transitions'),
'debounce' => (int) ($config->get('debounce') ?? 50),
'logLevel' => $config->get('log_level') ?? 'warnings',
'adminPreview' => (bool) $config->get('admin_preview'),
'activeBreakpoints' => ['sm', 'md', 'lg', 'xl', 'xxl'],
// ALWAYS inline for playground.
'renderingMode' => 'inline',
'csrfToken' => \Drupal::csrfToken()->get('utilikit-update-css'),
'breakpoints' => [
'sm' => 576,
'md' => 768,
'lg' => 992,
'xl' => 1200,
'xxl' => 1400,
],
];
// Always attach inline engine.
$attachments['#attached']['library'][] = 'utilikit/utilikit.engine';
if ($config->get('show_page_errors')) {
$attachments['#attached']['library'][] = 'utilikit/utilikit.engine.message';
}
if ($config->get('dev_mode')) {
$attachments['#attached']['library'][] = 'utilikit/utilikit.debug';
}
}
