You are here

BootstrapListGroupItemShortcode.php in Bootstrap 3 shortcodes 8

Adds shortcodes for all Bootstrap elements.

File

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

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

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

/**
 * @Shortcode(
 *   id = "bs_list_group_item",
 *   token = "list_group_item",
 *   title = @Translation("List Group Item"),
 *   description = @Translation("Bootstrap 3 shortcode"),
 *   weight = 50
 * )
 *
 * @author M. W. Delaney
 *
 */
class BootstrapListGroupItemShortcode extends ShortcodeBase {
  public function process(array $attributes, $content, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
    $attributes = $this
      ->getAttributes(array(
      'link' => '',
      'type' => '',
      'active' => '',
      'target' => '',
      'xclass' => '',
      'data' => '',
    ), $attributes);
    $class = 'list-group-item';
    $class .= $attributes['type'] ? ' list-group-item-' . $attributes['type'] : '';
    $class .= $attributes['active'] != '' ? ' active' : '';
    $class .= $attributes['xclass'] ? ' ' . $attributes['xclass'] : '';
    $data_props = _bs_shortcodes_parse_data_attributes($attributes['data']);
    return sprintf('<%1$s %2$s %3$s class="%4$s"%5$s>%6$s</%1$s>', $attributes['link'] ? 'a' : 'li', $attributes['link'] ? 'href="' . UrlHelper::stripDangerousProtocols($attributes['link']) . '"' : '', $attributes['target'] ? sprintf(' target="%s"', Html::escape($attributes['target'])) : '', Html::escape($class), $data_props ? ' ' . $data_props : '', $content);
  }

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

}

Classes

Namesort descending Description
BootstrapListGroupItemShortcode @Shortcode( id = "bs_list_group_item", token = "list_group_item", title = @Translation("List Group Item"), description = @Translation("Bootstrap 3 shortcode"), weight = 50 )