uikit_components.module in UIkit Components 7
Same filename and directory in other branches
UIkit Components.
Companion module to the UIkit base theme to provide additional components and functionality.
File
uikit_components.moduleView source
<?php
/**
* @file
* UIkit Components.
*
* Companion module to the UIkit base theme to provide additional components and
* functionality.
*/
/**
* Implements hook_help().
*/
function uikit_components_help($path, $arg) {
switch ($path) {
case 'admin/config/user-interface/uikit-components':
return '<p>' . t('TODO: Add help text and a configuration form for configurable settings.') . '</p>';
case 'admin/help#uikit_components':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The UIkit components module provides additional components and functionality to the UIkit base theme. Some aspects of the frontend cannot be themed without going through the backend, such as empty navbar links. With this module we can add more functionality to the UIkit frontend through the Drupal backend without the need for contributed modules which may add more functionality than needed.') . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Navbar special menu items') . '</dt>';
$output .= '<dd><p>' . t('When working with menus, UIkit navbars can contain special menu items such as headers, dividers and parent items with no path. Users with the <em>Administer menus and menu items</em> permission can create these special menu items by entering the corresponding text in the <em>Path</em> field when adding/editing links from the <a href="@menu">Menus</a> administration page.', array(
'@menu' => '/admin/structure/menu',
)) . '</p>';
$output .= '<p>Enter one of the following (including < and >) in the <em>Path</em> field to use the special menu item:</p>';
$output .= t('<ul><li><em><uk-nav-header></em>: Creates a menu item as a header</li><li><em><uk-nav-divider></em>: Creates a menu item as a separator</li><li><em><uk-parent></em>: Creates a parent menu item with no path to follow when clicked</li></ul>') . '</dd>';
$output .= '</dl>';
return $output;
}
}
/**
* Implements hook_menu().
*/
function uikit_components_menu() {
// The <uk-nav-header>, <uk-parent> and <uk-nav-divider> menu items allow us
// to enter these values in the path field when creating a new menu item so we
// can theme navbar menus correctly.
$items['<uk-nav-header>'] = array(
'page callback' => 'drupal_not_found',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['<uk-parent>'] = array(
'page callback' => 'drupal_not_found',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['<uk-nav-divider>'] = array(
'page callback' => 'drupal_not_found',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['admin/config/user-interface/uikit-components'] = array(
'title' => 'UIkit components',
'description' => 'Configure UIkit components.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'uikit_components_admin_settings_form',
),
'access arguments' => array(
'administer menu',
),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implements hook_theme().
*/
function uikit_components_theme($existing, $type, $theme, $path) {
return array(
'uikit_navbar' => array(
'variables' => array(
'menus' => NULL,
'menus_flipped' => NULL,
'attached' => FALSE,
),
),
);
}
function theme_uikit_navbar($variables) {
$menus = $variables['menus'];
$menus_flipped = $variables['menus_flipped'];
$attributes['class'][] = 'uk-navbar';
if ($variables['attached']) {
$attributes['class'][] = 'uk-navbar-attached';
}
$output = '';
if (!empty($menus) || !empty($menus_flipped)) {
// Navbar wrapper.
$output = '<nav' . drupal_attributes($attributes) . '>';
if (!empty($menus)) {
foreach ($menus as $menu) {
// Render menu trees for each menu.
$menu_tree = menu_tree($menu);
$menu_tree['#theme_wrappers'] = array(
'menu_tree__navbar',
);
$output .= render($menu_tree);
}
}
if (!empty($menus_flipped)) {
foreach ($menus_flipped as $menu_flip) {
// Render menu trees for each flipped menu.
$menu_tree_flip = menu_tree($menu_flip);
$menu_tree_flip['#theme_wrappers'] = array(
'menu_tree__navbar_flip',
);
$output .= render($menu_tree_flip);
}
}
$output .= '</nav>';
}
return $output;
}
/**
* System settings form builder for the uikit_components module.
*
* @return array
* Returns the system settings form.
*/
function uikit_components_admin_settings_form() {
$form = array();
return system_settings_form($form);
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function uikit_components_form_menu_edit_item_alter(&$form, &$form_state, $form_id) {
$link_path_description = t('The path for this menu link. This can be an internal path such as <em class="placeholder">node/add</em> or an external URL such as <em class="placeholder">http://example.com</em>. Enter <em class="placeholder"><front></em> to link to the front page, <em class="placeholder"><uk-nav-header></em> to create a header, <em class="placeholder"><uk-nav-divider></em> to create a separator, or <em class="placeholder"><uk-parent></em> to create a parent menu item with no link.');
$form['link_path']['#description'] = $link_path_description;
}
Functions
Name | Description |
---|---|
theme_uikit_navbar | |
uikit_components_admin_settings_form | System settings form builder for the uikit_components module. |
uikit_components_form_menu_edit_item_alter | Implements hook_form_FORM_ID_alter(). |
uikit_components_help | Implements hook_help(). |
uikit_components_menu | Implements hook_menu(). |
uikit_components_theme | Implements hook_theme(). |