Commit a246cf64 authored by Damien Tournoud's avatar Damien Tournoud

Implement a first version of the store-oriented IA.

Also disable shortcut module.

Change-Id: Ide0fc5ff54e2f66dacdc110c7f44f15235d8bc71
Reviewed-on: https://code.commerceguys.com/3563Reviewed-by: 's avatarHudson bot <bender@commerceguys.com>
Reviewed-by: 's avatarDamien Tournoud <damien@commerceguys.com>
parent 435d24c7
......@@ -11,6 +11,7 @@ dependencies[] = toolbar
; dependencies[] = devel
; dependencies[] = admin_menu
; dependencies[] = admin_menu_toolbar
; dependencies[] = shortcut
; Install necessary core modules.
dependencies[] = block
......@@ -25,7 +26,6 @@ dependencies[] = options
dependencies[] = path
dependencies[] = taxonomy
dependencies[] = dblog
dependencies[] = shortcut
dependencies[] = overlay
dependencies[] = field_ui
dependencies[] = file
......@@ -96,5 +96,6 @@ dependencies[] = commerce_kickstart_blog
dependencies[] = commerce_kickstart_blog_ui
dependencies[] = commerce_kickstart_merchandising
dependencies[] = commerce_kickstart_merchandising_ui
dependencies[] = commerce_kickstart_menus
files[] = commerce_kickstart.profile
......@@ -331,21 +331,6 @@ function _commerce_kickstart_install() {
// If Admin Menu is installed, collapse the module fieldsets.
variable_set('admin_menu_tweak_modules', TRUE);
// Add a shortcut set for store administration.
$set = new stdClass;
$set->title = st('Store administration');
$set->links = array(
array('link_path' => 'admin/commerce/products/add', 'link_title' => st('Add product')),
array('link_path' => 'node/add/product-display', 'link_title' => st('Add product display')),
array('link_path' => 'admin/commerce/products', 'link_title' => st('View products')),
array('link_path' => 'admin/commerce/orders', 'link_title' => st('View orders')),
array('link_path' => 'admin/commerce/config', 'link_title' => st('Configure store')),
);
shortcut_set_save($set);
// Apply the shortcut set to the first user.
shortcut_set_assign_user($set, (object) array('uid' => 1));
// Enable the addressbook on the "Billing information" checkout pane.
variable_set('commerce_customer_profile_billing_addressbook', TRUE);
}
......
name = "Commerce Kickstart Menus"
description = "Demonstrate how to customize the administrative menus."
core = "7.x"
package = "Kickstart"
dependencies[] = toolbar_megamenu
<?php
/**
* Implements hook_menu().
*/
function commerce_kickstart_menus_menu() {
$items['admin/commerce/layout'] = array(
'title' => 'Visual & Layout',
'description' => 'Administer the appearance and layout of your store.',
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('access administration pages'),
'file path' => drupal_get_path('module', 'system'),
'file' => 'system.admin.inc',
'weight' => 150,
);
$items['admin/commerce/site-config'] = array(
'title' => 'Site configuration',
'description' => 'Administer the site configuration.',
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('access administration pages'),
'file path' => drupal_get_path('module', 'system'),
'file' => 'system.admin.inc',
'weight' => 200,
);
return $items;
}
/**
* Implements hook_menu_alter().
*/
function commerce_kickstart_menus_menu_alter(&$items) {
// "Products" entry point.
if (isset($items['admin/commerce/products'])) {
$items['admin/commerce/products']['parent'] = 'admin';
$items['admin/commerce/products']['weight'] = -30;
}
// "Orders" entry point.
if (isset($items['admin/commerce/orders'])) {
$items['admin/commerce/orders']['parent'] = 'admin';
$items['admin/commerce/orders']['weight'] = -20;
}
// Disable "Customers" entry point.
if (isset($items['admin/commerce/customer-profiles'])) {
$items['admin/commerce/customer-profiles']['title'] = 'Customers';
$items['admin/commerce/customer-profiles']['hidden'] = 1;
}
// "Store" becomes the new entry point "Configure store".
if (isset($items['admin/commerce'])) {
$items['admin/commerce']['title'] = 'Configure store';
$items['admin/commerce']['weight'] = 50;
$items['admin/commerce']['options'] = array(
'toolbar_expanded' => TRUE,
);
}
// - "Configure" becomes the "Store settings" subentry
if (isset($items['admin/commerce/config'])) {
$items['admin/commerce/config']['title'] = 'Store settings';
$items['admin/commerce/config']['options'] = array(
'toolbar_expanded' => TRUE,
);
}
if (isset($items['admin/commerce/config/product-pricing'])) {
// Just because the default title 'Product pricing rules' is too long.
$items['admin/commerce/config/product-pricing']['title'] = 'Pricing rules';
}
// - Visual & Layout subentry.
if (isset($items['admin/commerce/layout'])) {
$items['admin/commerce/layout']['options'] = array(
'toolbar_expanded' => TRUE,
'toolbar_break' => TRUE,
);
}
// Move the appearance and layout entries under admin/commerce/layout.
foreach (array('admin/appearance', 'admin/structure/block', 'admin/structure/views') as $path) {
if (isset($items[$path])) {
$items[$path]['parent'] = 'admin/commerce/layout';
}
}
// - Site configuration subentry.
if (isset($items['admin/commerce/site-config'])) {
$items['admin/commerce/site-config']['options'] = array(
'toolbar_expanded' => TRUE,
'toolbar_break' => TRUE,
);
}
// Move the main Drupal entry points below admin/commerce/site-config.
foreach (array('admin/structure', 'admin/people', 'admin/modules', 'admin/config', 'admin/reports', 'admin/help', 'admin/advanced_help', 'admin/demo') as $path) {
if (isset($items[$path])) {
$items[$path]['parent'] = 'admin/commerce/site-config';
}
}
}
/**
* Implements hook_menu_link_alter().
*
* Apply some link configuration stored in the router during the menu
* rebuild process.
*/
function commerce_kickstart_menus_menu_link_alter(&$link) {
$item = _commerce_kickstart_menu_find_router($link['link_path']);
if ($item && isset($item['options'])) {
if (!isset($link['options'])) {
$link['options'] = array();
}
$link['options'] += $item['options'];
}
if ($item && isset($item['parent'])) {
$plid = db_query('SELECT mlid FROM {menu_links} WHERE link_path = :path', array(':path' => $item['parent']))->fetchField();
if ($plid) {
$link['plid'] = $plid;
}
}
}
function _commerce_kickstart_menu_find_router($link_path) {
$router = menu_get_router();
$parts = explode('/', $link_path, MENU_MAX_PARTS);
$ancestors = menu_get_ancestors($parts);
// Add an empty router path as a fallback.
$ancestors[] = '';
foreach ($ancestors as $key => $router_path) {
if (isset($router[$router_path])) {
// Exit the loop leaving $router_path as the first match.
break;
}
}
return isset($router[$router_path]) ? $router[$router_path] : NULL;
}
/**
* Implements hook_module_implements_alter().
*/
function commerce_kickstart_menus_module_implements_alter(&$implementations, $hook) {
if (in_array($hook, array('menu_alter'))) {
// Move our hook implementation to the bottom.
$group = $implementations['commerce_kickstart_menus'];
unset($implementations['commerce_kickstart_menus']);
$implementations['commerce_kickstart_menus'] = $group;
}
}
/**
* Someone please redo this thing completely.
*
* (start from scratch)
*/
#toolbar > div.toolbar-menu {
background-color: #333;
}
#toolbar > div.toolbar-menu {
}
#toolbar > div.toolbar-menu > div.toolbar-menu-wrapper > ul.group {
margin-right: 1.5em;
float: left;
}
#toolbar div.toolbar-menu-wrapper div.toolbar-menu-wrapper {
position: absolute;
top: -1000px;
margin-left: -10px;
background: #333;
border-radius: 0 0 5px 5px;
-moz-box-shadow: 0 3px 10px #000;
-webkit-box-shadow: 0 3px 10px #000;
box-shadow: 0 3px 10px #000;
padding: 1em;
opacity: 0;
z-index: -1;
}
#toolbar div.toolbar-menu-wrapper div.toolbar-menu-wrapper div.toolbar-menu-wrapper {
position: static;
background: transparent;
border-radius: none;
-moz-box-shadow: none;
-webkit-box-shadow: none;
box-shadow: none;
margin-left: 0;
padding: 0;
padding-left: 1em;
width: normal;
display: block;
opacity: 1;
}
#toolbar div.toolbar-menu ul li:hover a {
background: #444;
}
#toolbar div.toolbar-menu ul li:hover div a {
background: transparent;
}
#toolbar div.toolbar-menu-wrapper > ul.menu > li > div.toolbar-menu-wrapper {
-webkit-transition: 1s all;
-webkit-transition-delay: 1s;
-moz-transition: 1s all;
-moz-transition-delay: 1s;
-ms-transition: 1s all;
-ms-transition-delay: 1s;
-o-transition: 1s all;
-o-transition-delay: 1s;
transition: 1s all;
transition-delay: 1s;
}
#toolbar div.toolbar-menu-wrapper > ul.menu > li.open > div.toolbar-menu-wrapper,
#toolbar div.toolbar-menu-wrapper > ul.menu > li:hover > div.toolbar-menu-wrapper {
display: block;
opacity: 1;
top: 30px;
-webkit-transition-delay: 0s;
-ms-transition-delay: 0s;
transition-delay: 0s;
-moz-transition-delay: 0s;
-webkit-transition: 0.5s;
-ms-transition: 0.5s;
transition: 0.5s;
-moz-transition: 0.5s;
}
#toolbar div.toolbar-menu div.toolbar-menu-wrapper div.toolbar-menu-wrapper ul.menu li a {
color: #eee;
font-weight: bold;
-moz-border-radius: 0px;
-webkit-border-radius: 0px;
border-radius: 0px;
}
#toolbar div.toolbar-menu-wrapper div.toolbar-menu-wrapper div.toolbar-menu-wrapper ul.menu li a {
font-weight: normal;
color: #ccc;
background: transparent;
}
#toolbar div.toolbar-menu div.toolbar-menu-wrapper div.toolbar-menu-wrapper ul li a:focus,
#toolbar div.toolbar-menu div.toolbar-menu-wrapper div.toolbar-menu-wrapper ul li a:hover,
#toolbar div.toolbar-menu div.toolbar-menu-wrapper div.toolbar-menu-wrapper ul li a:active,
#toolbar div.toolbar-menu div.toolbar-menu-wrapper div.toolbar-menu-wrapper ul li a.active:focus {
background: transparent;
color: #fff;
}
#toolbar div.toolbar-menu div.toolbar-menu-wrapper div.toolbar-menu-wrapper ul li a.active:hover,
#toolbar div.toolbar-menu div.toolbar-menu-wrapper div.toolbar-menu-wrapper ul li a.active:active,
#toolbar div.toolbar-menu div.toolbar-menu-wrapper div.toolbar-menu-wrapper ul li a.active,
#toolbar div.toolbar-menu div.toolbar-menu-wrapper div.toolbar-menu-wrapper ul li.active-trail a {
background: transparent;
text-shadow: none;
color: #fff;
}
#toolbar ul.menu ul.menu li a {
float: none;
display: block;
}
#toolbar ul.menu ul.menu li {
float: none;
}
#toolbar div.toolbar-menu-wrapper div.toolbar-menu-wrapper .group {
width: 10em;
float: left;
}
name = Toolbar Megamenu
description = "Extension of Toolbar to support dropdown megamenus."
core = 7.x
dependencies[] = toolbar
<?php
/**
* Implements hook_page_build().
*/
function toolbar_megamenu_page_build(&$page) {
if (isset($page['page_top']['toolbar'])) {
$page['page_top']['toolbar']['#pre_render'] = array('toolbar_megamenu_pre_render');
}
}
/**
* Prerender function for the toolbar.
*/
function toolbar_megamenu_pre_render($toolbar) {
$toolbar = array_merge($toolbar, toolbar_megamenu_view());
return $toolbar;
}
/**
* Builds the admin menu as a structured array ready for drupal_render().
*
* @return
* Array of links and settings relating to the admin menu.
*/
function toolbar_megamenu_view() {
global $user;
$module_path = drupal_get_path('module', 'toolbar');
$megamenu_path = drupal_get_path('module', 'toolbar_megamenu');
$build = array(
'#theme' => 'toolbar',
'#attached'=> array(
'js' => array(
$module_path . '/toolbar.js',
array(
'data' => array('tableHeaderOffset' => 'Drupal.toolbar.height'),
'type' => 'setting'
),
),
'css' => array(
$module_path . '/toolbar.css',
$megamenu_path . '/toolbar_megamenu.css',
),
'library' => array(array('system', 'jquery.cookie')),
),
);
// Retrieve the admin menu from the database.
$build['toolbar_menu'] = toolbar_megamenu_tree_output(toolbar_megamenu_get_menu_tree());
$build['toolbar_menu']['#prefix'] .= '<h2 class="element-invisible">' . t('Administrative toolbar') . '</h2>';
// Add logout & user account links or login link.
if ($user->uid) {
$links = array(
'account' => array(
'title' => t('Hello <strong>@username</strong>', array('@username' => format_username($user))),
'href' => 'user',
'html' => TRUE,
'attributes' => array('title' => t('User account')),
),
'logout' => array(
'title' => t('Log out'),
'href' => 'user/logout',
),
);
}
else {
$links = array(
'login' => array(
'title' => t('Log in'),
'href' => 'user',
),
);
}
$build['toolbar_user'] = array(
'#theme' => 'links__toolbar_user',
'#links' => $links,
'#attributes' => array('id' => 'toolbar-user'),
);
// Add a "home" link.
$link = array(
'home' => array(
'title' => '<span class="home-link">Home</span>',
'href' => '<front>',
'html' => TRUE,
'attributes' => array('title' => t('Home')),
),
);
$build['toolbar_home'] = array(
'#theme' => 'links',
'#links' => $link,
'#attributes' => array('id' => 'toolbar-home'),
);
// Add an anchor to be able to toggle the visibility of the drawer.
$build['toolbar_toggle'] = array(
'#theme' => 'toolbar_toggle',
'#collapsed' => _toolbar_is_collapsed(),
'#attributes' => array('class' => array('toggle')),
);
// Prepare the drawer links CSS classes.
$toolbar_drawer_classes = array(
'toolbar-drawer',
'clearfix',
);
if (_toolbar_is_collapsed()) {
$toolbar_drawer_classes[] = 'collapsed';
}
$build['toolbar_drawer_classes'] = implode(' ', $toolbar_drawer_classes);
return $build;
}
/**
* Gets the main items below the admin path.
*/
function toolbar_megamenu_get_menu_tree() {
$tree = array();
$admin_link = db_query('SELECT * FROM {menu_links} WHERE menu_name = :menu_name AND module = :module AND link_path = :path', array(':menu_name' => 'management', ':module' => 'system', ':path' => 'admin'))->fetchAssoc();
if ($admin_link) {
$tree = menu_build_tree('management', array(
'expanded' => array_merge(array($admin_link['mlid']), array_keys(variable_get('toolbar_megamenu', array()))),
'min_depth' => $admin_link['depth'] + 1,
'max_depth' => $admin_link['depth'] + 3,
));
}
return $tree;
}
function toolbar_megamenu_tree_output($tree, $balance = TRUE) {
$build = array();
$groups = array();
// Build the groups up-front so that we get proper grouping and accurate
// counts for the first/last classes.
$current_group = 0;
foreach ($tree as $data) {
// Break to a new group (even for non-visible items), but only if the
// current group is not empty.
if (!empty($data['link']['options']['toolbar_break']) && !empty($groups[$current_group])) {
$current_group++;
}
if ($data['link']['access'] && !$data['link']['hidden']) {
$groups[$current_group][] = $data;
}
}
$router_item = menu_get_item();
foreach ($groups as $current_group => $items) {
$num_items = count($items);
foreach ($items as $i => $data) {
$class = array();
if ($i == 0) {
$class[] = 'first';
}
if ($i == $num_items - 1) {
$class[] = 'last';
}
// Set a class for the <li>-tag. Since $data['below'] may contain local
// tasks, only set 'expanded' class if the link also has children within
// the current menu.
if ($data['link']['has_children'] && $data['below']) {
$class[] = 'expanded';
}
elseif ($data['link']['has_children']) {
$class[] = 'collapsed';
}
else {
$class[] = 'leaf';
}
// Set a class if the link is in the active trail.
if ($data['link']['in_active_trail']) {
$class[] = 'active-trail';
$data['link']['localized_options']['attributes']['class'][] = 'active-trail';
}
// Normally, l() compares the href of every link with $_GET['q'] and sets
// the active class accordingly. But local tasks do not appear in menu
// trees, so if the current path is a local task, and this link is its
// tab root, then we have to set the class manually.
if ($data['link']['href'] == $router_item['tab_root_href'] && $data['link']['href'] != $_GET['q']) {
$data['link']['localized_options']['attributes']['class'][] = 'active';
}
// Allow menu-specific theme overrides.
$element['#theme'] = 'menu_link__' . strtr($data['link']['menu_name'], '-', '_');
$element['#attributes']['class'] = $class;
$element['#title'] = $data['link']['title'];
$element['#href'] = $data['link']['href'];
$element['#localized_options'] = !empty($data['link']['localized_options']) ? $data['link']['localized_options'] : array();
$element['#below'] = $data['below'] ? toolbar_megamenu_tree_output($data['below'], FALSE) : $data['below'];
$element['#original_link'] = $data['link'];
// Index using the link's unique mlid.
$build[$current_group][$data['link']['mlid']] = $element;
}
}
if ($build) {
foreach (element_children($build) as $group_id) {
$build[$group_id] += array(
'#sorted' => TRUE,
'#prefix' => '<ul class="menu group group-' . $group_id . '">',
'#suffix' => '</ul>',
);
}
// Make sure drupal_render() does not re-order the links.
$build['#sorted'] = TRUE;
// Add the theme wrapper for outer markup.
// Allow menu-specific theme overrides.
$build += array(
'#prefix' => '<div class="toolbar-menu-wrapper">',
'#suffix' => '</div>',
);
}
return $build;
}
/**
* Implements hook_form_FORM_ID_alter().
*
* @see menu_edit_item().
*/
function toolbar_megamenu_form_menu_edit_item_alter(&$form, &$form_state) {
$item = $form['original_item']['#value'];
$item['options'] += array(
'toolbar_expanded' => FALSE,
'toolbar_break' => FALSE,
);
$form['toolbar'] = array('#tree' => TRUE, '#weight' => 10);
$form['actions']['#weight'] = 200;
$form['toolbar']['toolbar_expanded'] = array(
'#type' => 'checkbox',
'#title' => t('Show as expanded in the toolbar'),
'#default_value' => $item['options']['toolbar_expanded'],
);
$form['toolbar']['toolbar_break'] = array(
'#type' => 'checkbox',
'#title' => t('Break column in the toolbar'),
'#default_value' => $item['options']['toolbar_break'],
);
$form['toolbar']['#element_validate'] = array('toolbar_megamenu_form_menu_edit_item_validate');
}
function toolbar_megamenu_form_menu_edit_item_validate($element, &$form_state, &$form) {
$form_state['values']['options']['toolbar_expanded'] = $element['toolbar_expanded']['#value'];
$form_state['values']['options']['toolbar_break'] = $element['toolbar_break']['#value'];
}
/**
* Implements hook_menu_link_insert().
*/
function toolbar_megamenu_menu_link_insert($link) {
_toolbar_megamenu_maintain_expanded_list($link);
}
/**
* Implements hook_menu_link_update().
*/
function toolbar_megamenu_menu_link_update($link) {
_toolbar_megamenu_maintain_expanded_list($link);
}
function _toolbar_megamenu_maintain_expanded_list($link) {
$expanded = variable_get('toolbar_megamenu', array());
if (!empty($link['options']['toolbar_expanded']) && empty($expanded[$link['mlid']])) {
$expanded[$link['mlid']] = TRUE;
variable_set('toolbar_megamenu', $expanded);
}
elseif (empty($link['options']['toolbar_expanded']) && !empty($expanded[$link['mlid']])) {
unset($expanded[$link['mlid']]);
variable_set('toolbar_megamenu', $expanded);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment