BootstrapCodeShortcode.php in Bootstrap 3 shortcodes 8
Adds shortcodes for all Bootstrap elements.
Namespace
Drupal\bs_shortcodes\Plugin\ShortcodeFile
src/Plugin/Shortcode/BootstrapCodeShortcode.phpView source
<?php
/**
* @file
* Adds shortcodes for all Bootstrap elements.
*/
namespace Drupal\bs_shortcodes\Plugin\Shortcode;
use Drupal\Component\Utility\Html;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Core\Language\Language;
use Drupal\shortcode\Plugin\ShortcodeBase;
/**
* @Shortcode(
* id = "bs_code",
* token = "code",
* title = @Translation("code"),
* description = @Translation("Bootstrap 3 shortcode"),
* weight = 50
* )
*
* @author Filip Stefansson
* @since 1.0
*
*/
class BootstrapCodeShortcode extends ShortcodeBase {
public function process(array $attributes, $content, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
$attributes = $this
->getAttributes(array(
'inline' => '',
'scrollable' => '',
'xclass' => '',
'data' => '',
), $attributes);
$class = '';
$class .= $attributes['scrollable'] != '' ? ' pre-scrollable' : '';
$class .= $attributes['xclass'] ? ' ' . $attributes['xclass'] : '';
$data_props = _bs_shortcodes_parse_data_attributes($attributes['data']);
return sprintf('<%1$s class="%2$s"%3$s>%4$s</%1$s>', $attributes['inline'] ? 'code' : 'pre', Html::escape($class), $data_props ? ' ' . $data_props : '', $content);
}
/**
* {@inheritdoc}
*/
public function tips($long = FALSE) {
$output = array();
$output[] = '<p><strong>[code</strong> inline="true, <u>false</u>" scrollable="true, <u>false</u>" xclass="any text" data="any text"<strong>]</strong> ... <strong>[/code]</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#code',
)) . '.</p>';
}
else {
$output[] = t('More info <a href=":url" target="_blank">here</a>', array(
':url' => 'https://github.com/MWDelaney/bootstrap-3-shortcodes#code',
)) . '.</p>';
}
return implode(' ', $output);
}
}
Classes
Name![]() |
Description |
---|---|
BootstrapCodeShortcode | @Shortcode( id = "bs_code", token = "code", title = @Translation("code"), description = @Translation("Bootstrap 3 shortcode"), weight = 50 ) |