I thought it would be nice to specify the icon and button style desired in hook_preprocess_links().

Attached is a patch that does just that.


$variables['links'][0] = array(
  'title' => 'button title',
  'path' => 'node/4',
  'icon' => 'plus',
  'button' => 'success',
  'size' => 'large'
);

results in

button title

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jon Pugh’s picture

Jon Pugh’s picture

Status: Active » Needs review
Jon Pugh’s picture

FileSize
1.28 KB

Updated path to hide notices.

markhalliwell’s picture

Status: Needs review » Needs work
  1. +++ b/templates/system/links.vars.php
    @@ -8,6 +8,36 @@
    +    $icon = $link['icon'];
    

    $link['icon'] may not exist. Needs an isset().

  2. +++ b/templates/system/links.vars.php
    @@ -8,6 +8,36 @@
    +      $icon_html = "<span class='glyphicon glyphicon-{$icon}'></span> ";
    

    This assumes the icon is glyphicon based. If $link['icon'] is provided it should be assumed that it is the full rendered icon, either using theme('icon') from Icon API or _bootstrap_icon() when creating the links.

  3. +++ b/templates/system/links.vars.php
    @@ -8,6 +8,36 @@
    +      $link['title'] = $icon_html .' '. $link['title'];
    

    This assumes the icon should be placed before the title. There should also be a check for $link['icon_placement'] which has one of the two possibilities: before or after.

  4. +++ b/templates/system/links.vars.php
    @@ -8,6 +8,36 @@
    +    if (isset($link['button'])) {
    +      $link['attributes']['class'][] = 'btn btn-' . $link['button'];
    +    }
    

    Separate issue.

  5. +++ b/templates/system/links.vars.php
    @@ -8,6 +8,36 @@
    +    if (isset($link['size'])) {
    +      switch ($link['size']) {
    +        case "large":
    +        case "lg":
    +          $link['attributes']['class'][] = "btn-lg";
    +          break;
    +        case "medium":
    +        case "md":
    +          $link['attributes']['class'][] = "btn-md";
    +          break;
    +        case "small":
    +        case "sm":
    +          $link['attributes']['class'][] = "btn-sm";
    +          break;
    +      }
    +    }
    +  }
    

    This needs to be, and is, a separate issue.

markhalliwell’s picture

Title: In theme_links, allow setting of "icon", "button", and "size" property » Allow detection of icons in theme_links

The button stuff is just simple classes, so when one is constructing the links to begin with they can just pass in the attributes themselves. The icon feature still makes sense though.

markhalliwell’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#2840791: Add icon support to "link" theme hook

This has been implemented as a backport of 8.x-3.x code.