BootstrapAlertShortcode.php in Bootstrap 3 shortcodes 8
Adds shortcodes for all Bootstrap elements.
Namespace
Drupal\bs_shortcodes\Plugin\ShortcodeFile
src/Plugin/Shortcode/BootstrapAlertShortcode.phpView 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_alert",
* token = "alert",
* title = @Translation("Alert"),
* description = @Translation("Bootstrap 3 shortcode"),
* weight = 50
* )
*
* @author Filip Stefansson
* @since 1.0
*
*/
class BootstrapAlertShortcode extends ShortcodeBase {
public function process(array $attributes, $content, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
$attributes = $this
->getAttributes(array(
'type' => '',
'dismissable' => '',
'xclass' => '',
'data' => '',
), $attributes);
$class = 'alert';
$class .= $attributes['type'] ? ' alert-' . $attributes['type'] : ' alert-success';
$class .= $attributes['dismissable'] != '' ? ' alert-dismissable' : '';
$class .= $attributes['xclass'] ? ' ' . $attributes['xclass'] : '';
$dismissable = $attributes['dismissable'] ? '<button type="button" class="close" data-dismiss="alert" aria-hidden="TRUE">×</button>' : '';
$data_props = _bs_shortcodes_parse_data_attributes($attributes['data']);
return sprintf('<div class="%s"%s>%s%s</div>', Html::escape($class), $data_props ? ' ' . $data_props : '', $dismissable, $content);
}
/**
* {@inheritdoc}
*/
public function tips($long = FALSE) {
$output = array();
$output[] = '<p><strong>[alert type="</strong><u>success</u>, info, warning, danger<strong>"</strong> dismissable="true, <u>false</u>" xclass="any text" data="any text"<strong>]</strong> ... <strong>[/alert]</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#alerts',
)) . '.</p>';
}
else {
$output[] = t('More info <a href=":url" target="_blank">here</a>', array(
':url' => 'https://github.com/MWDelaney/bootstrap-3-shortcodes#alerts',
)) . '.</p>';
}
return implode(' ', $output);
}
}
Classes
Name![]() |
Description |
---|---|
BootstrapAlertShortcode | @Shortcode( id = "bs_alert", token = "alert", title = @Translation("Alert"), description = @Translation("Bootstrap 3 shortcode"), weight = 50 ) |