You are here

BootstrapButtonGroupShortcode.php in Bootstrap 3 shortcodes 8

Adds shortcodes for all Bootstrap elements.

File

src/Plugin/Shortcode/BootstrapButtonGroupShortcode.php
View source
<?php

/**
 * @file
 * Adds shortcodes for all Bootstrap elements.
 */
namespace Drupal\bs_shortcodes\Plugin\Shortcode;

use Drupal\Component\Utility\Html;
use Drupal\Core\Language\Language;
use Drupal\shortcode\Plugin\ShortcodeBase;

/**
 * @Shortcode(
 *   id = "bs_button_group",
 *   token = "button_group",
 *   title = @Translation("Button Group"),
 *   description = @Translation("Bootstrap 3 shortcode"),
 *   weight = 50 
 * )
 *
 * @author M. W. Delaney
 *
 */
class BootstrapButtonGroupShortcode extends ShortcodeBase {
  public function process(array $attributes, $content, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
    $attributes = $this
      ->getAttributes(array(
      'size' => '',
      'vertical' => '',
      'justified' => '',
      'dropup' => '',
      'xclass' => '',
      'data' => '',
    ), $attributes);
    $class = 'btn-group';
    $class .= $attributes['size'] ? ' btn-group-' . $attributes['size'] : '';
    $class .= $attributes['vertical'] != '' ? ' btn-group-vertical' : '';
    $class .= $attributes['justified'] != '' ? ' btn-group-justified' : '';
    $class .= $attributes['dropup'] != '' ? ' dropup' : '';
    $class .= $attributes['xclass'] ? ' ' . $attributes['xclass'] : '';
    $data_props = _bs_shortcodes_parse_data_attributes($attributes['data']);
    return sprintf('<div class="%s"%s>%s</div>', Html::escape($class), $data_props ? ' ' . $data_props : '', $content);
  }

  /**
   * {@inheritdoc}
   */
  public function tips($long = FALSE) {
    $output = array();
    $output[] = '<p><strong>[button_group</strong> size="xs, sm, lg" justified="true, <u>false</u>" vertical="true, <u>false</u>" dropup="true, <u>false</u>" xclass="any text" data="any text"<strong>]</strong>  ... <strong>[/button_group]</strong>';
    if ($long) {
      $output[] = t('More info about this shortcode <a href=":url" target="_blank">here</a>', array(
        ':url' => 'https://github.com/MWDelaney/bootstrap-3-shortcodes#button-groups',
      )) . '.</p>';
    }
    else {
      $output[] = t('More info <a href=":url" target="_blank">here</a>', array(
        ':url' => 'https://github.com/MWDelaney/bootstrap-3-shortcodes#button-groups',
      )) . '.</p>';
    }
    return implode(' ', $output);
  }

}

Classes

Namesort descending Description
BootstrapButtonGroupShortcode @Shortcode( id = "bs_button_group", token = "button_group", title = @Translation("Button Group"), description = @Translation("Bootstrap 3 shortcode"), weight = 50 )