BootstrapDropdownItemShortcode.php in Bootstrap 3 shortcodes 8
Adds shortcodes for all Bootstrap elements.
Namespace
Drupal\bs_shortcodes\Plugin\ShortcodeFile
src/Plugin/Shortcode/BootstrapDropdownItemShortcode.phpView 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_dropdown_item",
* token = "dropdown_item",
* title = @Translation("Dropdown Item"),
* description = @Translation("Bootstrap 3 shortcode")
* )
*
* @author M. W. Delaney
*
*/
class BootstrapDropdownItemShortcode extends ShortcodeBase {
public function process(array $attributes, $content, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
$attributes = $this
->getAttributes(array(
'link' => '',
'disabled' => '',
'xclass' => '',
'data' => '',
), $attributes);
$li_class = '';
$li_class .= $attributes['disabled'] != '' ? ' disabled' : '';
$a_class = '';
$a_class .= $attributes['xclass'] ? ' ' . $attributes['xclass'] : '';
$data_props = _bs_shortcodes_parse_data_attributes($attributes['data']);
return sprintf('<li role="presentation" class="%s"><a role="menuitem" href="%s" class="%s"%s>%s</a></li>', Html::escape($li_class), UrlHelper::stripDangerousProtocols($attributes['link']), Html::escape($a_class), $data_props ? ' ' . $data_props : '', $content);
}
/**
* {@inheritdoc}
*/
public function tips($long = FALSE) {
$output = array();
$output[] = '<p><strong>[dropdown_item</strong> link="any valid link" disabled="true, <u>false</u>" xclass="any text" data="any text"<strong>]</strong> ... <strong>[/dropdown_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#dropdown-item-parameters',
)) . '.</p>';
}
else {
$output[] = t('More info <a href=":url" target="_blank">here</a>', array(
':url' => 'https://github.com/MWDelaney/bootstrap-3-shortcodes#dropdown-item-parameters',
)) . '.</p>';
}
return implode(' ', $output);
}
}
Classes
Name![]() |
Description |
---|---|
BootstrapDropdownItemShortcode | @Shortcode( id = "bs_dropdown_item", token = "dropdown_item", title = @Translation("Dropdown Item"), description = @Translation("Bootstrap 3 shortcode") ) |