By markhalliwell on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
7.x-3.x
Introduced in version:
7.x-3.1
Issue links:
Description:
While the bootstrap_btn_dropdown theme hook was "technically" converted, it never really went under any real scrutiny. Nor does it really allow the many different features defined in Bootstrap documentation:
http://getbootstrap.com/components/#dropdowns
http://getbootstrap.com/components/#btn-dropdowns
http://getbootstrap.com/javascript/#dropdowns
The following issues were addressed and improved:
- Renamed
bootstrap_btn_dropdowntobootstrap_dropdown. This theme hook name was inaccurate and misleading. Not all dropdown toggles are a button. - Label processing.
- Attribute/class processing.
- Removed legacy and unused
bootstrap_linkstheme hook for item list processing - Added dropdown alignment options.
- Added support for detecting headers and divider items.
If you happen to have code that uses these old functions, please refactor them to use the bootstrap_dropdown theme hook instead:
// This is an example of how to create complex dropdowns using render arrays
// as items. See how to create simple links in the last example at the bottom.
$items = array();
// Create headers using #markup and #header.
$items[] = array(
'#markup' => _bootstrap_icon('envelope') . ' ' . t('Notifications'),
'#header' => TRUE,
);
$items[] = array(
'#type' => 'link',
'#title' => t('Messages'),
'#href' => 'messages',
'#options' => array(
'html' => TRUE,
),
);
// Created dividers by passing NULL or and empty string ('') as the item.
$items[] = NULL;
$items[] = array(
'#markup' => _bootstrap_icon('user') . ' ' . t('My Account'),
'#header' => TRUE,
);
$items[] = array(
'#type' => 'link',
'#title' => t('View profile'),
'#href' => 'user',
'#options' => array(
'html' => TRUE,
),
);
$items[] = array(
'#type' => 'link',
'#title' => t('Logout'),
'#href' => 'user/logout',
);
// Example of using bootstrap_dropdown in render arrays. Because render arrays
// typically defer rendering until the last possible second, this allows the
// array to be altered if needed. This is the preferred method.
$dropdown = array(
'#theme' => 'bootstrap_dropdown',
// By default if you pass text (string) as the toggle, it will be converted
// to an empty link (href="#"). You can, however, pass a render array
// instead if a different element is needed (like a button).
'#toggle' => array(
'#type' => 'button',
'#value' => format_username($GLOBALS['user']) . ' ' . _bootstrap_icon('chevron-down'),
),
// Use the above complex items array.
'#items' => $items,
// Default styling causes dropdowns to position below and on the left edge
// of the toggle. If you need to change the alignment you can pass either
// of the following as alignments: "right" or "up".
'#alignment' => array('right'),
);
print drupal_render($dropdown);
// This second example shows how to use it with theme(). Note: because this
// theme hook renders as an element, you need to pass all variables (prefixed
// with a hash (#)) inside an element variable. This method is not preferred.
print theme('bootstrap_dropdown', array(
'element' => array(
'#toggle' => t('Links') . ' ' . _bootstrap_icon('chevron-down'),
// Despite how this dropdown is rendered, passing simple links as items
// would work for both rendering methods. Below you can see a very simple
// array of links.
'#items' => array(
l(t('Drupal.org'), 'http://drupal.org'),
l(t('Drupal Groups'), 'http://groups.drupal.org'),
l(t('Drupal API'), 'http://api.drupal.org'),
),
),
));
Impacts:
Site builders, administrators, editors
Module developers
Themers