You are here

class BootstrapCollapseShortcode in Bootstrap 3 shortcodes 8

@Shortcode( id = "bs_collapse", token = "collapse", title = @Translation("Collapse"), description = @Translation("Bootstrap 3 shortcode"), weight = 50 )

@author Filip Stefansson @since 1.0

Hierarchy

Expanded class hierarchy of BootstrapCollapseShortcode

File

src/Plugin/Shortcode/BootstrapCollapseShortcode.php, line 25
Adds shortcodes for all Bootstrap elements.

Namespace

Drupal\bs_shortcodes\Plugin\Shortcode
View source
class BootstrapCollapseShortcode extends ShortcodeBase {
  public function process(array $attributes, $content, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
    $attributes = $this
      ->getAttributes(array(
      'title' => '',
      'type' => '',
      'active' => '',
      'xclass' => '',
      'data' => '',
    ), $attributes);
    $panel_class = 'panel';
    $panel_class .= $attributes['type'] ? ' panel-' . $attributes['type'] : ' panel-default';
    $panel_class .= $attributes['xclass'] ? ' ' . $attributes['xclass'] : '';
    $collapse_class = 'panel-collapse';
    $collapse_class .= $attributes['active'] != '' ? ' in' : ' collapse';
    if (!isset($GLOBALS['collapsibles_count'])) {
      $GLOBALS['collapsibles_count'] = 0;
    }
    $parent = 'custom-collapse-' . $GLOBALS['collapsibles_count'];
    $current_collapse = $parent . '-' . Html::escape($attributes['title']);
    $data_props = _bs_shortcodes_parse_data_attributes($attributes['data']);
    return sprintf('<div class="%1$s"%2$s>
        <div class="panel-heading">
          <h4 class="panel-title">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#%3$s" href="#%4$s">%5$s</a>
          </h4>
        </div>
        <div id="%4$s" class="%6$s">
          <div class="panel-body">%7$s</div>
        </div>
      </div>', Html::escape($panel_class), $data_props ? ' ' . $data_props : '', $parent, Html::getUniqueId($current_collapse), $attributes['title'], Html::escape($collapse_class), $content);
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
BootstrapCollapseShortcode::process public function Performs the shortcode processing. Overrides ShortcodeInterface::process
BootstrapCollapseShortcode::tips public function Generates a filter's tip. Overrides ShortcodeBase::tips
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
ShortcodeBase::$pluginId protected property The plugin ID of this filter. Overrides PluginBase::$pluginId
ShortcodeBase::$provider public property The name of the provider that owns this filter.
ShortcodeBase::$settings public property An associative array containing the configured settings of this filter.
ShortcodeBase::$status public property A Boolean indicating whether this filter is enabled.
ShortcodeBase::addClass public function Add a class into a classes string if not already inside.
ShortcodeBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
ShortcodeBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
ShortcodeBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration
ShortcodeBase::getAttributes public function Combines user attributes with known attributes.
ShortcodeBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
ShortcodeBase::getDescription public function Returns the administrative description for this shortcode plugin. Overrides ShortcodeInterface::getDescription
ShortcodeBase::getImageProperties public function Returns image properties for a given image media entity id.
ShortcodeBase::getLabel public function Returns the administrative label for this shortcode plugin. Overrides ShortcodeInterface::getLabel
ShortcodeBase::getMediaField public function Get a media entity field.
ShortcodeBase::getMediaFileUrl public function Get the file url for a media object.
ShortcodeBase::getMidFromPath public function Extracts the media id from a 'media/x' system path.
ShortcodeBase::getTitleFromAttributes public function Returns a suitable title string given the user provided title and text.
ShortcodeBase::getType public function
ShortcodeBase::getUrlFromPath public function Returns a url to be used in a link element given path or url.
ShortcodeBase::render public function Wrapper for renderPlain.
ShortcodeBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
ShortcodeBase::settingsForm public function Generates a shortcode's settings form. Overrides ShortcodeInterface::settingsForm
ShortcodeBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.