You are here

BootstrapLabelShortcode.php in Bootstrap 3 shortcodes 8

Adds shortcodes for all Bootstrap elements.

File

src/Plugin/Shortcode/BootstrapLabelShortcode.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_label",
 *   token = "label",
 *   title = @Translation("Label"),
 *   description = @Translation("Bootstrap 3 shortcode"),
 *   weight = 50
 * )
 *
 * @author Filip Stefansson
 * @since 1.0
 *
 */
class BootstrapLabelShortcode extends ShortcodeBase {
  public function process(array $attributes, $content, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
    $attributes = $this
      ->getAttributes(array(
      'type' => '',
      'xclass' => '',
      'data' => '',
    ), $attributes);
    $class = 'label';
    $class .= $attributes['type'] ? ' label-' . $attributes['type'] : ' label-default';
    $class .= $attributes['xclass'] ? ' ' . $attributes['xclass'] : '';
    $data_props = _bs_shortcodes_parse_data_attributes($attributes['data']);
    return sprintf('<span class="%s"%s>%s</span>', Html::escape($class), $data_props ? ' ' . $data_props : '', $content);
  }

  /**
   * {@inheritdoc}
   */
  public function tips($long = FALSE) {
    $output = array();
    $output[] = '<p><strong>[label</strong> type="<u>default</u>, primary, success, info, warning, danger" xclass="any text" data="any text"<strong>]</strong>  ... <strong>[/label]</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#labels',
      )) . '.</p>';
    }
    else {
      $output[] = t('More info <a href=":url" target="_blank">here</a>', array(
        ':url' => 'https://github.com/MWDelaney/bootstrap-3-shortcodes#labels',
      )) . '.</p>';
    }
    return implode(' ', $output);
  }

}

Classes

Namesort descending Description
BootstrapLabelShortcode @Shortcode( id = "bs_label", token = "label", title = @Translation("Label"), description = @Translation("Bootstrap 3 shortcode"), weight = 50 )