Example #1
0
/**
 * Overrides theme_menu_local_action().
 *
 * Overrides Bootstrap module's override. All we're doing is making the action
 * link buttons bigger by removing the 'btn-xs' class.
 *
 * @see bootstrap_menu_local_action()
 */
function bootstrap_material_menu_local_action($variables)
{
    $link = $variables['element']['#link'];
    $options = isset($link['localized_options']) ? $link['localized_options'] : array();
    // If the title is not HTML, sanitize it.
    if (empty($options['html'])) {
        $link['title'] = check_plain($link['title']);
    }
    $icon = _bootstrap_iconize_text($link['title']);
    // Format the action link.
    $output = '';
    if (isset($link['href'])) {
        // Turn link into a mini-button and colorize based on title.
        if ($class = _bootstrap_colorize_text($link['title'])) {
            if (!isset($options['attributes']['class'])) {
                $options['attributes']['class'] = array();
            }
            $string = is_string($options['attributes']['class']);
            if ($string) {
                $options['attributes']['class'] = explode(' ', $options['attributes']['class']);
            }
            $options['attributes']['class'][] = 'btn';
            $options['attributes']['class'][] = 'btn-' . $class;
            if ($string) {
                $options['attributes']['class'] = implode(' ', $options['attributes']['class']);
            }
        }
        // Force HTML so we can render any icon that may have been added.
        $options['html'] = !empty($options['html']) || !empty($icon) ? TRUE : FALSE;
        $output .= l($icon . $link['title'], $link['href'], $options);
    } else {
        $output .= $icon . $link['title'];
    }
    return $output;
}
/**
 * Returns HTML for a single local action link.
 *
 * @param array $variables
 *   An associative array containing:
 *   - element: A render element containing:
 *     - #link: A menu link array with 'title', 'href', and 'localized_options'
 *       keys.
 *
 * @return string
 *   The constructed HTML.
 *
 * @see theme_menu_local_action()
 *
 * @ingroup theme_functions
 */
function bootstrap_preprocess_menu_local_action(&$variables)
{
    $link = $variables['element']['#link'];
    $link += array('localized_options' => array());
    $link['localized_options']['set_active_class'] = TRUE;
    $icon = _bootstrap_iconize_text($link['title']);
    $options = isset($link['localized_options']) ? $link['localized_options'] : array();
    if (isset($link['url'])) {
        // Turn link into a mini-button and colorize based on title.
        if ($class = _bootstrap_colorize_text($link['title'])) {
            if (!isset($options['attributes']['class'])) {
                $options['attributes']['class'] = array();
            }
            $string = is_string($options['attributes']['class']);
            if ($string) {
                $options['attributes']['class'] = explode(' ', $options['attributes']['class']);
            }
            $options['attributes']['class'][] = 'btn';
            $options['attributes']['class'][] = 'btn-xs';
            $options['attributes']['class'][] = 'btn-' . $class;
            if ($string) {
                $options['attributes']['class'] = implode(' ', $options['attributes']['class']);
            }
        }
        $variables['link'] = array('#type' => 'link', '#title' => SafeMarkup::format($icon . '@text', array('@text' => $link['title'])), '#options' => $options, '#url' => $link['url']);
    } else {
        $variables['link'] = array('#type' => 'link', '#title' => $link['title'], '#options' => $options, '#url' => $link['url']);
    }
}
/**
 * Returns HTML for a single local action link.
 *
 * @param array $variables
 *   An associative array containing:
 *   - element: A render element containing:
 *     - #link: A menu link array with 'title', 'href', and 'localized_options'
 *       keys.
 *
 * @return string
 *   The constructed HTML.
 *
 * @see theme_menu_local_action()
 *
 * @ingroup theme_functions
 */
function bootstrap_menu_local_action($variables)
{
    $link = $variables['element']['#link'];
    $title = $link['title'];
    $icon = _bootstrap_iconize_text($title);
    $href = !empty($link['href']) ? $link['href'] : FALSE;
    $options = isset($link['localized_options']) ? $link['localized_options'] : array();
    // Format the action link.
    if ($href) {
        // Turn link into a mini-button and colorize based on title.
        if ($class = _bootstrap_colorize_text($title)) {
            if (!isset($options['attributes']['class'])) {
                $options['attributes']['class'] = array();
            }
            $string = is_string($options['attributes']['class']);
            if ($string) {
                $options['attributes']['class'] = explode(' ', $options['attributes']['class']);
            }
            $options['attributes']['class'][] = 'btn';
            $options['attributes']['class'][] = 'btn-xs';
            $options['attributes']['class'][] = 'btn-' . $class;
            if ($string) {
                $options['attributes']['class'] = implode(' ', $options['attributes']['class']);
            }
        }
        // Force HTML so we can render any icon that may have been added.
        $options['html'] = !empty($options['html']) || !empty($icon) ? TRUE : FALSE;
    }
    // Filter the title if the "html" is set, otherwise l() will automatically
    // sanitize using check_plain(), so no need to call that here.
    if (!empty($options['html'])) {
        $title = _bootstrap_filter_xss($title);
    }
    return $href ? l($icon . $title, $href, $options) : $icon . $title;
}