/**
  * {@inheritdoc}
  */
 public function preprocessElement(Element $element, Variables $variables)
 {
     $link = $element->getProperty('link');
     $link += ['localized_options' => []];
     $link['localized_options']['set_active_class'] = TRUE;
     $icon = Bootstrap::glyphiconFromString($link['title']);
     $options = isset($link['localized_options']) ? $link['localized_options'] : [];
     if (isset($link['url'])) {
         // Turn link into a mini-button and colorize based on title.
         $class = Bootstrap::cssClassFromString($link['title'], 'default');
         if (!isset($options['attributes']['class'])) {
             $options['attributes']['class'] = [];
         }
         $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'] = ['#type' => 'link', '#title' => SafeMarkup::format(\Drupal::service('renderer')->render($icon) . '@text', ['@text' => $link['title']]), '#options' => $options, '#url' => $link['url']];
     } else {
         $variables['link'] = ['#type' => 'link', '#title' => $link['title'], '#options' => $options, '#url' => $link['url']];
     }
 }
Beispiel #2
0
/**
 * Matches a Bootstrap Glyphicon based on a string value.
 *
 * @param string $string
 *   The string to match classes against.
 * @param string $default
 *   The default icon to return if no match is found.
 *
 * @return string
 *   The Bootstrap icon matched against the value of $haystack or $default if
 *   no match could be made.
 *
 * @deprecated Will be removed in a future release.
 *
 * @code
 *   // Before.
 *   $icon = _bootstrap_iconize_text($string, $default);
 *
 *   // After.
 *   use Drupal\bootstrap\Bootstrap;
 *   $icon = Bootstrap::glyphiconFromString($string, ['#markup' => $default]);
 * @endcode
 *
 * @see \Drupal\bootstrap\Bootstrap::glyphiconFromString()
 */
function _bootstrap_iconize_text($string, $default = '')
{
    Bootstrap::deprecated();
    return Bootstrap::glyphiconFromString($string, ['#markup' => $default]);
}
Beispiel #3
0
 /**
  * Adds an icon to button element based on its text value.
  *
  * @param array $icon
  *   An icon render array.
  *
  * @return $this
  *
  * @see \Drupal\bootstrap\Bootstrap::glyphicon()
  */
 public function setIcon(array $icon = NULL)
 {
     if ($this->isButton() && !Bootstrap::getTheme()->getSetting('button_iconize')) {
         return $this;
     }
     $icon = isset($icon) ? $icon : Bootstrap::glyphiconFromString($this->getProperty('value'));
     $this->setProperty('icon', $icon);
     return $this;
 }