uikit_views.module in UIkit Components 8.2
Same filename and directory in other branches
UIkit Views.
Companion module to the UIkit base theme to provide Views plugins.
File
uikit_views/uikit_views.moduleView source
<?php
use Drupal\Core\Routing\RouteMatchInterface;
/**
* @file
* UIkit Views.
*
* Companion module to the UIkit base theme to provide Views plugins.
*/
use Drupal\Core\Url;
use Drupal\uikit_views\UIkitViews;
use Drupal\views\ViewExecutable;
/**
* Implements hook_help().
*/
function uikit_views_help($route_name, RouteMatchInterface $route_match) {
$output = '';
// Setup translatable string arguments.
$t_args = [
':uikit' => Url::fromUri('https://www.drupal.org/project/uikit')
->toString(),
// Current plugin style components.
':accordion' => Url::fromUri('https://getuikit.com/v2/docs/accordion.html')
->toString(),
':grid' => Url::fromUri('https://getuikit.com/v2/docs/grid.html')
->toString(),
':list' => Url::fromUri('https://getuikit.com/v2/docs/list.html')
->toString(),
':table' => Url::fromUri('https://getuikit.com/v2/docs/table.html')
->toString(),
// @todo Future plugin style components. See https://www.drupal.org/node/2893295
':nav' => Url::fromUri('https://getuikit.com/v2/docs/nav.html')
->toString(),
':subnav' => Url::fromUri('https://getuikit.com/v2/docs/subnav.html')
->toString(),
':slideshow' => Url::fromUri('https://getuikit.com/v2/docs/slideshow.html')
->toString(),
':slider' => Url::fromUri('https://getuikit.com/v2/docs/slider.html')
->toString(),
':slideset' => Url::fromUri('https://getuikit.com/v2/docs/slideset.html')
->toString(),
':switcher' => Url::fromUri('https://getuikit.com/v2/docs/switcher.html')
->toString(),
':lightbox' => Url::fromUri('https://getuikit.com/v2/docs/lightbox.html')
->toString(),
];
switch ($route_name) {
case 'help.page.uikit_views':
$output = '<p>' . t('The UIkit Views module provides Views plugins for the <a href=":uikit" target="_blank">UIkit theme</a>.', $t_args) . '</p>';
$output .= '<h3>' . t('Views plugins') . '</h3>';
$output .= '<p>' . t('<strong>Style</strong>: Style plugins control how a view is displayed. For the most part they are object wrappers around theme templates. Styles UIkit Views provides:') . '</p>';
$output .= '<ul>';
$output .= '<li>' . t('<a href=":accordion" target="_blank">Accordion</a>', $t_args) . '</li>';
$output .= '<li>' . t('<a href=":grid" target="_blank">Grid</a>', $t_args) . '</li>';
$output .= '<li>' . t('<a href=":list" target="_blank">List</a>', $t_args) . '</li>';
$output .= '<li>' . t('<a href=":table" target="_blank">Table</a>', $t_args) . '</li>';
$output .= '</ul>';
$output .= '<p><strong>Styles proposed for future inclusion:</strong></p>';
$output .= '<ul>';
$output .= '<li>' . t('<a href=":nav" target="_blank">Nav</a>', $t_args) . '</li>';
$output .= '<li>' . t('<a href=":subnav" target="_blank">Subnav</a>', $t_args) . '</li>';
$output .= '<li>' . t('<a href=":slideshow" target="_blank">Slidshow</a>', $t_args) . '</li>';
$output .= '<li>' . t('<a href=":slider" target="_blank">Slider</a>', $t_args) . '</li>';
$output .= '<li>' . t('<a href=":slideset" target="_blank">Slideset</a>', $t_args) . '</li>';
$output .= '<li>' . t('<a href=":switcher" target="_blank">Switcher</a>', $t_args) . '</li>';
$output .= '<li>' . t('<a href=":lightbox" target="_blank">Lightbox</a>', $t_args) . '</li>';
$output .= '</ul>';
break;
}
return $output;
}
/**
* Implements hook_theme().
*/
function uikit_views_theme($existing, $type, $theme, $path) {
return UIkitViews::getThemeHooks();
}
/**
* Implements hook_theme_registry_alter().
*/
function uikit_views_theme_registry_alter(&$theme_registry) {
$module_path = drupal_get_path('module', 'uikit_views');
// Alter the path so we can put templates into separate directories.
$theme_registry['uikit_view_accordion']['path'] = $module_path . '/templates/views';
$theme_registry['uikit_view_grid']['path'] = $module_path . '/templates/views';
$theme_registry['uikit_view_list']['path'] = $module_path . '/templates/views';
$theme_registry['uikit_view_table']['path'] = $module_path . '/templates/views';
}
/**
* Implements hook_views_preview_info_alter().
*/
function uikit_views_views_preview_info_alter(array &$rows, ViewExecutable $view) {
$style = $view
->getStyle();
$plugin_id = $style
->getPluginId();
// UIkit Components views plugin styles.
$uikit_plugins = [
'uikit_view_accordion',
'uikit_view_grid',
'uikit_view_list',
'uikit_view_table',
];
if (in_array($plugin_id, $uikit_plugins)) {
// Attach the UIkit library so views previews are styled correctly.
$view->element['#attached']['library'][] = "uikit_views/uikit";
}
}
Functions
Name | Description |
---|---|
uikit_views_help | Implements hook_help(). |
uikit_views_theme | Implements hook_theme(). |
uikit_views_theme_registry_alter | Implements hook_theme_registry_alter(). |
uikit_views_views_preview_info_alter | Implements hook_views_preview_info_alter(). |