4 * Contains \Drupal\bootstrap\Bootstrap.
7 namespace Drupal\bootstrap;
9 use Drupal\bootstrap\Plugin\AlterManager;
10 use Drupal\bootstrap\Plugin\FormManager;
11 use Drupal\bootstrap\Plugin\PreprocessManager;
12 use Drupal\bootstrap\Utility\Element;
13 use Drupal\bootstrap\Utility\Unicode;
14 use Drupal\Component\Utility\Html;
15 use Drupal\Component\Utility\NestedArray;
16 use Drupal\Core\Extension\ThemeHandlerInterface;
17 use Drupal\Core\Form\FormStateInterface;
20 * The primary class for the Drupal Bootstrap base theme.
22 * Provides many helper methods.
29 * Tag used to invalidate caches.
33 const CACHE_TAG = 'theme_registry';
40 const CALLBACK_APPEND = 1;
47 const CALLBACK_PREPEND = 2;
50 * Replace a callback or append it if not found.
54 const CALLBACK_REPLACE_APPEND = 3;
57 * Replace a callback or prepend it if not found.
61 const CALLBACK_REPLACE_PREPEND = 4;
64 * The current supported Bootstrap Framework version.
68 const FRAMEWORK_VERSION = '3.3.7';
71 * The Bootstrap Framework documentation site.
75 const FRAMEWORK_HOMEPAGE = 'http://getbootstrap.com';
78 * The Bootstrap Framework repository.
82 const FRAMEWORK_REPOSITORY = 'https://github.com/twbs/bootstrap';
89 const PROJECT_BRANCH = '8.x-3.x';
92 * The Drupal Bootstrap documentation site.
96 const PROJECT_DOCUMENTATION = 'http://drupal-bootstrap.org';
99 * The Drupal Bootstrap project page.
103 const PROJECT_PAGE = 'https://www.drupal.org/project/bootstrap';
106 * Adds a callback to an array.
108 * @param array $callbacks
109 * An array of callbacks to add the callback to, passed by reference.
110 * @param array|string $callback
111 * The callback to add.
112 * @param array|string $replace
113 * If specified, the callback will instead replace the specified value
114 * instead of being appended to the $callbacks array.
116 * Flag that determines how to add the callback to the array.
119 * TRUE if the callback was added, FALSE if $replace was specified but its
120 * callback could be found in the list of callbacks.
122 public static function addCallback(array &$callbacks, $callback, $replace = NULL, $action = Bootstrap::CALLBACK_APPEND) {
123 // Replace a callback.
125 // Iterate through the callbacks.
126 foreach ($callbacks as $key => $value) {
127 // Convert each callback and match the string values.
128 if (Unicode::convertCallback($value) === Unicode::convertCallback($replace)) {
129 $callbacks[$key] = $callback;
133 // No match found and action shouldn't append or prepend.
134 if ($action !== self::CALLBACK_REPLACE_APPEND || $action !== self::CALLBACK_REPLACE_PREPEND) {
139 // Append or prepend the callback.
141 case self::CALLBACK_APPEND:
142 case self::CALLBACK_REPLACE_APPEND:
143 $callbacks[] = $callback;
146 case self::CALLBACK_PREPEND:
147 case self::CALLBACK_REPLACE_PREPEND:
148 array_unshift($callbacks, $callback);
157 * Manages theme alter hooks as classes and allows sub-themes to sub-class.
159 * @param string $function
160 * The procedural function name of the alter (e.g. __FUNCTION__).
162 * The variable that was passed to the hook_TYPE_alter() implementation to
163 * be altered. The type of this variable depends on the value of the $type
164 * argument. For example, when altering a 'form', $data will be a structured
165 * array. When altering a 'profile', $data will be an object.
166 * @param mixed $context1
167 * (optional) An additional variable that is passed by reference.
168 * @param mixed $context2
169 * (optional) An additional variable that is passed by reference. If more
170 * context needs to be provided to implementations, then this should be an
171 * associative array as described above.
173 public static function alter($function, &$data, &$context1 = NULL, &$context2 = NULL) {
175 if (!isset($theme)) {
176 $theme = self::getTheme();
179 // Immediately return if the active theme is not Bootstrap based.
180 if (!$theme->isBootstrap()) {
184 // Extract the alter hook name.
185 $hook = Unicode::extractHook($function, 'alter');
187 // Handle form alters as a separate plugin.
188 if (strpos($hook, 'form') === 0 && $context1 instanceof FormStateInterface) {
189 $form_state = $context1;
190 $form_id = $context2;
192 // Due to a core bug that affects admin themes, we should not double
193 // process the "system_theme_settings" form twice in the global
194 // hook_form_alter() invocation.
195 // @see https://drupal.org/node/943212
196 if ($form_id === 'system_theme_settings') {
200 // Keep track of the form identifiers.
203 // Get the build data.
204 $build_info = $form_state->getBuildInfo();
206 // Extract the base_form_id.
207 $base_form_id = !empty($build_info['base_form_id']) ? $build_info['base_form_id'] : FALSE;
209 $ids[] = $base_form_id;
212 // If there was no provided form identifier, extract it.
214 $form_id = !empty($build_info['form_id']) ? $build_info['form_id'] : Unicode::extractHook($function, 'alter', 'form');
220 // Retrieve a list of form definitions.
221 $form_manager = new FormManager($theme);
223 // Iterate over each form identifier and look for a possible plugin.
224 foreach ($ids as $id) {
225 /** @var \Drupal\bootstrap\Plugin\Form\FormInterface $form */
226 if ($form_manager->hasDefinition($id) && ($form = $form_manager->createInstance($id, ['theme' => $theme]))) {
227 $data['#submit'][] = [get_class($form), 'submitForm'];
228 $data['#validate'][] = [get_class($form), 'validateForm'];
229 $form->alterForm($data, $form_state, $form_id);
233 // Process hook alter normally.
235 // Retrieve a list of alter definitions.
236 $alter_manager = new AlterManager($theme);
238 /** @var \Drupal\bootstrap\Plugin\Alter\AlterInterface $class */
239 if ($alter_manager->hasDefinition($hook) && ($class = $alter_manager->createInstance($hook, ['theme' => $theme]))) {
240 $class->alter($data, $context1, $context2);
246 * Returns a documentation search URL for a given query.
248 * @param string $query
249 * The query to search for.
252 * The complete URL to the documentation site.
254 public static function apiSearchUrl($query = '') {
255 return self::PROJECT_DOCUMENTATION . '/api/bootstrap/' . self::PROJECT_BRANCH . '/search/' . Html::escape($query);
259 * Returns the autoload fix include path.
261 * This method assists class based callbacks that normally do not work.
263 * If you notice that your class based callback is never invoked, you may try
264 * using this helper method as an "include" or "file" for your callback, if
265 * the callback metadata supports such an option.
267 * Depending on when or where a callback is invoked during a request, such as
268 * an ajax or batch request, the theme handler may not yet be fully
271 * Typically there is little that can be done about this "issue" from core.
272 * It must balance the appropriate level that should be bootstrapped along
273 * with common functionality. Cross-request class based callbacks are not
276 * When this file is included, it will attempt to jump start this process.
278 * Please keep in mind, that it is merely an attempt and does not guarantee
279 * that it will actually work. If it does not appear to work, do not use it.
281 * @see \Drupal\Core\Extension\ThemeHandler::listInfo
282 * @see \Drupal\Core\Extension\ThemeHandler::systemThemeList
284 * @see system_register()
285 * @see drupal_classloader_register()
288 * The autoload fix include path, relative to Drupal root.
290 public static function autoloadFixInclude() {
291 return static::getTheme('bootstrap')->getPath() . '/autoload-fix.php';
295 * Matches a Bootstrap class based on a string value.
297 * @param string|array $value
298 * The string to match against to determine the class. Passed by reference
299 * in case it is a render array that needs to be rendered and typecast.
300 * @param string $default
301 * The default class to return if no match is found.
304 * The Bootstrap class matched against the value of $haystack or $default
305 * if no match could be made.
307 public static function cssClassFromString(&$value, $default = '') {
310 $lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
313 $theme = static::getTheme();
314 $texts = $theme->getCache('cssClassFromString', [$lang]);
316 // Ensure it's a string value that was passed.
317 $string = static::toString($value);
319 if ($texts->isEmpty()) {
321 // Text that match these specific strings are checked first.
324 t('Download feature')->render() => 'primary',
327 t('Add effect')->render() => 'success',
328 t('Add and configure')->render() => 'success',
329 t('Save configuration')->render() => 'success',
330 t('Install and set as default')->render() => 'success',
333 t('Save and add')->render() => 'info',
334 t('Add another item')->render() => 'info',
335 t('Update style')->render() => 'info',
338 // Text containing these words anywhere in the string are checked last.
341 t('Confirm')->render() => 'primary',
342 t('Filter')->render() => 'primary',
343 t('Log in')->render() => 'primary',
344 t('Submit')->render() => 'primary',
345 t('Search')->render() => 'primary',
346 t('Settings')->render() => 'primary',
347 t('Upload')->render() => 'primary',
350 t('Delete')->render() => 'danger',
351 t('Remove')->render() => 'danger',
352 t('Uninstall')->render() => 'danger',
355 t('Add')->render() => 'success',
356 t('Create')->render() => 'success',
357 t('Install')->render() => 'success',
358 t('Save')->render() => 'success',
359 t('Write')->render() => 'success',
362 t('Export')->render() => 'warning',
363 t('Import')->render() => 'warning',
364 t('Restore')->render() => 'warning',
365 t('Rebuild')->render() => 'warning',
368 t('Apply')->render() => 'info',
369 t('Update')->render() => 'info',
373 // Allow sub-themes to alter this array of patterns.
374 /** @var \Drupal\Core\Theme\ThemeManager $theme_manager */
375 $theme_manager = \Drupal::service('theme.manager');
376 $theme_manager->alter('bootstrap_colorize_text', $data);
378 $texts->setMultiple($data);
381 // Iterate over the array.
382 foreach ($texts as $pattern => $strings) {
383 foreach ($strings as $text => $class) {
386 if ($string === $text) {
392 if (strpos(Unicode::strtolower($string), Unicode::strtolower($text)) !== FALSE) {
400 // Return the default if nothing was matched.
405 * Logs and displays a warning about a deprecated function/method being used.
407 public static function deprecated() {
409 $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
410 \Drupal::logger('bootstrap')->warning('<pre><code>' . print_r($backtrace, TRUE) . '</code></pre>');
412 if (!self::getTheme()->getSetting('suppress_deprecated_warnings')) {
416 // Extrapolate the caller.
417 $caller = $backtrace[1];
419 if (isset($caller['class'])) {
420 $parts = explode('\\', $caller['class']);
421 $class = array_pop($parts) . '::';
423 drupal_set_message(t('The following function(s) or method(s) have been deprecated, please check the logs for a more detailed backtrace on where these are being invoked. Click on the function or method link to search the documentation site for a possible replacement or solution.'), 'warning');
424 drupal_set_message(t('<a href=":url" target="_blank">@title</a>.', [
425 ':url' => self::apiSearchUrl($class . $caller['function']),
426 '@title' => ($class ? $caller['class'] . $caller['type'] : '') . $caller['function'] . '()',
431 * Provides additional variables to be used in elements and templates.
434 * An associative array containing key/default value pairs.
436 public static function extraVariables() {
438 // @see https://drupal.org/node/2035055
441 // @see https://drupal.org/node/2219965
443 'icon_position' => 'before',
444 'icon_only' => FALSE,
449 * Retrieves a theme instance of \Drupal\bootstrap.
451 * @param string $name
452 * The machine name of a theme. If omitted, the active theme will be used.
453 * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
454 * The theme handler object.
456 * @return \Drupal\bootstrap\Theme
459 public static function getTheme($name = NULL, ThemeHandlerInterface $theme_handler = NULL) {
460 // Immediately return if theme passed is already instantiated.
461 if ($name instanceof Theme) {
466 static $active_theme;
467 if (!isset($active_theme)) {
468 $active_theme = \Drupal::theme()->getActiveTheme()->getName();
471 $name = $active_theme;
474 if (!isset($theme_handler)) {
475 $theme_handler = self::getThemeHandler();
478 if (!isset($themes[$name])) {
479 $themes[$name] = new Theme($theme_handler->getTheme($name), $theme_handler);
482 return $themes[$name];
486 * Retrieves the theme handler instance.
488 * @return \Drupal\Core\Extension\ThemeHandlerInterface
489 * The theme handler instance.
491 public static function getThemeHandler() {
492 static $theme_handler;
493 if (!isset($theme_handler)) {
494 $theme_handler = \Drupal::service('theme_handler');
496 return $theme_handler;
500 * Returns the theme hook definition information.
502 * This base-theme's custom theme hook implementations. Never define "path"
503 * as this is automatically detected and added.
505 * @see \Drupal\bootstrap\Plugin\Alter\ThemeRegistry::alter()
506 * @see bootstrap_theme_registry_alter()
507 * @see bootstrap_theme()
510 public static function getThemeHooks() {
511 $hooks['bootstrap_carousel'] = [
516 'indicators' => TRUE,
525 $hooks['bootstrap_dropdown'] = [
527 'alignment' => 'down',
535 $hooks['bootstrap_modal'] = [
539 'body_attributes' => [],
540 'close_button' => TRUE,
541 'content_attributes' => [],
542 'description' => NULL,
543 'description_display' => 'before',
544 'dialog_attributes' => [],
546 'footer_attributes' => [],
547 'header_attributes' => [],
551 'title_attributes' => [],
555 $hooks['bootstrap_panel'] = [
559 'body_attributes' => [],
560 'collapsible' => FALSE,
561 'collapsed' => FALSE,
562 'description' => NULL,
563 'description_display' => 'before',
565 'footer_attributes' => [],
567 'heading_attributes' => [],
569 'panel_type' => 'default',
577 * Returns a specific Bootstrap Glyphicon.
579 * @param string $name
580 * The icon name, minus the "glyphicon-" prefix.
581 * @param array $default
582 * (Optional) The default render array to use if $name is not available.
585 * The render containing the icon defined by $name, $default value if
586 * icon does not exist or returns NULL if no icon could be rendered.
588 public static function glyphicon($name, $default = []) {
591 // Ensure the icon specified is a valid Bootstrap Glyphicon.
592 // @todo Supply a specific version to _bootstrap_glyphicons() when Icon API
593 // supports versioning.
594 if (self::getTheme()->hasGlyphicons() && in_array($name, self::glyphicons())) {
595 // Attempt to use the Icon API module, if enabled and it generates output.
596 if (\Drupal::moduleHandler()->moduleExists('icon')) {
599 '#bundle' => 'bootstrap',
600 '#icon' => 'glyphicon-' . $name,
605 '#type' => 'html_tag',
609 'class' => ['icon', 'glyphicon', 'glyphicon-' . $name],
610 'aria-hidden' => 'true',
616 return $icon ?: $default;
620 * Matches a Bootstrap Glyphicon based on a string value.
622 * @param string $value
623 * The string to match against to determine the icon. Passed by reference
624 * in case it is a render array that needs to be rendered and typecast.
625 * @param array $default
626 * The default render array to return if no match is found.
629 * The Bootstrap icon matched against the value of $haystack or $default if
630 * no match could be made.
632 public static function glyphiconFromString(&$value, $default = []) {
635 $lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
638 $theme = static::getTheme();
639 $texts = $theme->getCache('glyphiconFromString', [$lang]);
641 // Ensure it's a string value that was passed.
642 $string = static::toString($value);
644 if ($texts->isEmpty()) {
646 // Text that match these specific strings are checked first.
649 // Text containing these words anywhere in the string are checked last.
651 t('Manage')->render() => 'cog',
652 t('Configure')->render() => 'cog',
653 t('Settings')->render() => 'cog',
654 t('Download')->render() => 'download',
655 t('Export')->render() => 'export',
656 t('Filter')->render() => 'filter',
657 t('Import')->render() => 'import',
658 t('Save')->render() => 'ok',
659 t('Update')->render() => 'ok',
660 t('Edit')->render() => 'pencil',
661 t('Uninstall')->render() => 'trash',
662 t('Install')->render() => 'plus',
663 t('Write')->render() => 'plus',
664 t('Cancel')->render() => 'remove',
665 t('Delete')->render() => 'trash',
666 t('Remove')->render() => 'trash',
667 t('Search')->render() => 'search',
668 t('Upload')->render() => 'upload',
669 t('Preview')->render() => 'eye-open',
670 t('Log in')->render() => 'log-in',
674 // Allow sub-themes to alter this array of patterns.
675 /** @var \Drupal\Core\Theme\ThemeManager $theme_manager */
676 $theme_manager = \Drupal::service('theme.manager');
677 $theme_manager->alter('bootstrap_iconize_text', $data);
679 $texts->setMultiple($data);
682 // Iterate over the array.
683 foreach ($texts as $pattern => $strings) {
684 foreach ($strings as $text => $icon) {
687 if ($string === $text) {
688 return self::glyphicon($icon, $default);
693 if (strpos(Unicode::strtolower($string), Unicode::strtolower($text)) !== FALSE) {
694 return self::glyphicon($icon, $default);
701 // Return a default icon if nothing was matched.
706 * Returns a list of available Bootstrap Framework Glyphicons.
708 * @param string $version
709 * The specific version of glyphicons to return. If not set, the latest
710 * BOOTSTRAP_VERSION will be used.
713 * An associative array of icons keyed by their classes.
715 public static function glyphicons($version = NULL) {
717 if (!isset($versions)) {
719 $versions['3.0.0'] = [
721 'glyphicon-adjust' => 'adjust',
722 'glyphicon-align-center' => 'align-center',
723 'glyphicon-align-justify' => 'align-justify',
724 'glyphicon-align-left' => 'align-left',
725 'glyphicon-align-right' => 'align-right',
726 'glyphicon-arrow-down' => 'arrow-down',
727 'glyphicon-arrow-left' => 'arrow-left',
728 'glyphicon-arrow-right' => 'arrow-right',
729 'glyphicon-arrow-up' => 'arrow-up',
730 'glyphicon-asterisk' => 'asterisk',
731 'glyphicon-backward' => 'backward',
732 'glyphicon-ban-circle' => 'ban-circle',
733 'glyphicon-barcode' => 'barcode',
734 'glyphicon-bell' => 'bell',
735 'glyphicon-bold' => 'bold',
736 'glyphicon-book' => 'book',
737 'glyphicon-bookmark' => 'bookmark',
738 'glyphicon-briefcase' => 'briefcase',
739 'glyphicon-bullhorn' => 'bullhorn',
740 'glyphicon-calendar' => 'calendar',
741 'glyphicon-camera' => 'camera',
742 'glyphicon-certificate' => 'certificate',
743 'glyphicon-check' => 'check',
744 'glyphicon-chevron-down' => 'chevron-down',
745 'glyphicon-chevron-left' => 'chevron-left',
746 'glyphicon-chevron-right' => 'chevron-right',
747 'glyphicon-chevron-up' => 'chevron-up',
748 'glyphicon-circle-arrow-down' => 'circle-arrow-down',
749 'glyphicon-circle-arrow-left' => 'circle-arrow-left',
750 'glyphicon-circle-arrow-right' => 'circle-arrow-right',
751 'glyphicon-circle-arrow-up' => 'circle-arrow-up',
752 'glyphicon-cloud' => 'cloud',
753 'glyphicon-cloud-download' => 'cloud-download',
754 'glyphicon-cloud-upload' => 'cloud-upload',
755 'glyphicon-cog' => 'cog',
756 'glyphicon-collapse-down' => 'collapse-down',
757 'glyphicon-collapse-up' => 'collapse-up',
758 'glyphicon-comment' => 'comment',
759 'glyphicon-compressed' => 'compressed',
760 'glyphicon-copyright-mark' => 'copyright-mark',
761 'glyphicon-credit-card' => 'credit-card',
762 'glyphicon-cutlery' => 'cutlery',
763 'glyphicon-dashboard' => 'dashboard',
764 'glyphicon-download' => 'download',
765 'glyphicon-download-alt' => 'download-alt',
766 'glyphicon-earphone' => 'earphone',
767 'glyphicon-edit' => 'edit',
768 'glyphicon-eject' => 'eject',
769 'glyphicon-envelope' => 'envelope',
770 'glyphicon-euro' => 'euro',
771 'glyphicon-exclamation-sign' => 'exclamation-sign',
772 'glyphicon-expand' => 'expand',
773 'glyphicon-export' => 'export',
774 'glyphicon-eye-close' => 'eye-close',
775 'glyphicon-eye-open' => 'eye-open',
776 'glyphicon-facetime-video' => 'facetime-video',
777 'glyphicon-fast-backward' => 'fast-backward',
778 'glyphicon-fast-forward' => 'fast-forward',
779 'glyphicon-file' => 'file',
780 'glyphicon-film' => 'film',
781 'glyphicon-filter' => 'filter',
782 'glyphicon-fire' => 'fire',
783 'glyphicon-flag' => 'flag',
784 'glyphicon-flash' => 'flash',
785 'glyphicon-floppy-disk' => 'floppy-disk',
786 'glyphicon-floppy-open' => 'floppy-open',
787 'glyphicon-floppy-remove' => 'floppy-remove',
788 'glyphicon-floppy-save' => 'floppy-save',
789 'glyphicon-floppy-saved' => 'floppy-saved',
790 'glyphicon-folder-close' => 'folder-close',
791 'glyphicon-folder-open' => 'folder-open',
792 'glyphicon-font' => 'font',
793 'glyphicon-forward' => 'forward',
794 'glyphicon-fullscreen' => 'fullscreen',
795 'glyphicon-gbp' => 'gbp',
796 'glyphicon-gift' => 'gift',
797 'glyphicon-glass' => 'glass',
798 'glyphicon-globe' => 'globe',
799 'glyphicon-hand-down' => 'hand-down',
800 'glyphicon-hand-left' => 'hand-left',
801 'glyphicon-hand-right' => 'hand-right',
802 'glyphicon-hand-up' => 'hand-up',
803 'glyphicon-hd-video' => 'hd-video',
804 'glyphicon-hdd' => 'hdd',
805 'glyphicon-header' => 'header',
806 'glyphicon-headphones' => 'headphones',
807 'glyphicon-heart' => 'heart',
808 'glyphicon-heart-empty' => 'heart-empty',
809 'glyphicon-home' => 'home',
810 'glyphicon-import' => 'import',
811 'glyphicon-inbox' => 'inbox',
812 'glyphicon-indent-left' => 'indent-left',
813 'glyphicon-indent-right' => 'indent-right',
814 'glyphicon-info-sign' => 'info-sign',
815 'glyphicon-italic' => 'italic',
816 'glyphicon-leaf' => 'leaf',
817 'glyphicon-link' => 'link',
818 'glyphicon-list' => 'list',
819 'glyphicon-list-alt' => 'list-alt',
820 'glyphicon-lock' => 'lock',
821 'glyphicon-log-in' => 'log-in',
822 'glyphicon-log-out' => 'log-out',
823 'glyphicon-magnet' => 'magnet',
824 'glyphicon-map-marker' => 'map-marker',
825 'glyphicon-minus' => 'minus',
826 'glyphicon-minus-sign' => 'minus-sign',
827 'glyphicon-move' => 'move',
828 'glyphicon-music' => 'music',
829 'glyphicon-new-window' => 'new-window',
830 'glyphicon-off' => 'off',
831 'glyphicon-ok' => 'ok',
832 'glyphicon-ok-circle' => 'ok-circle',
833 'glyphicon-ok-sign' => 'ok-sign',
834 'glyphicon-open' => 'open',
835 'glyphicon-paperclip' => 'paperclip',
836 'glyphicon-pause' => 'pause',
837 'glyphicon-pencil' => 'pencil',
838 'glyphicon-phone' => 'phone',
839 'glyphicon-phone-alt' => 'phone-alt',
840 'glyphicon-picture' => 'picture',
841 'glyphicon-plane' => 'plane',
842 'glyphicon-play' => 'play',
843 'glyphicon-play-circle' => 'play-circle',
844 'glyphicon-plus' => 'plus',
845 'glyphicon-plus-sign' => 'plus-sign',
846 'glyphicon-print' => 'print',
847 'glyphicon-pushpin' => 'pushpin',
848 'glyphicon-qrcode' => 'qrcode',
849 'glyphicon-question-sign' => 'question-sign',
850 'glyphicon-random' => 'random',
851 'glyphicon-record' => 'record',
852 'glyphicon-refresh' => 'refresh',
853 'glyphicon-registration-mark' => 'registration-mark',
854 'glyphicon-remove' => 'remove',
855 'glyphicon-remove-circle' => 'remove-circle',
856 'glyphicon-remove-sign' => 'remove-sign',
857 'glyphicon-repeat' => 'repeat',
858 'glyphicon-resize-full' => 'resize-full',
859 'glyphicon-resize-horizontal' => 'resize-horizontal',
860 'glyphicon-resize-small' => 'resize-small',
861 'glyphicon-resize-vertical' => 'resize-vertical',
862 'glyphicon-retweet' => 'retweet',
863 'glyphicon-road' => 'road',
864 'glyphicon-save' => 'save',
865 'glyphicon-saved' => 'saved',
866 'glyphicon-screenshot' => 'screenshot',
867 'glyphicon-sd-video' => 'sd-video',
868 'glyphicon-search' => 'search',
869 'glyphicon-send' => 'send',
870 'glyphicon-share' => 'share',
871 'glyphicon-share-alt' => 'share-alt',
872 'glyphicon-shopping-cart' => 'shopping-cart',
873 'glyphicon-signal' => 'signal',
874 'glyphicon-sort' => 'sort',
875 'glyphicon-sort-by-alphabet' => 'sort-by-alphabet',
876 'glyphicon-sort-by-alphabet-alt' => 'sort-by-alphabet-alt',
877 'glyphicon-sort-by-attributes' => 'sort-by-attributes',
878 'glyphicon-sort-by-attributes-alt' => 'sort-by-attributes-alt',
879 'glyphicon-sort-by-order' => 'sort-by-order',
880 'glyphicon-sort-by-order-alt' => 'sort-by-order-alt',
881 'glyphicon-sound-5-1' => 'sound-5-1',
882 'glyphicon-sound-6-1' => 'sound-6-1',
883 'glyphicon-sound-7-1' => 'sound-7-1',
884 'glyphicon-sound-dolby' => 'sound-dolby',
885 'glyphicon-sound-stereo' => 'sound-stereo',
886 'glyphicon-star' => 'star',
887 'glyphicon-star-empty' => 'star-empty',
888 'glyphicon-stats' => 'stats',
889 'glyphicon-step-backward' => 'step-backward',
890 'glyphicon-step-forward' => 'step-forward',
891 'glyphicon-stop' => 'stop',
892 'glyphicon-subtitles' => 'subtitles',
893 'glyphicon-tag' => 'tag',
894 'glyphicon-tags' => 'tags',
895 'glyphicon-tasks' => 'tasks',
896 'glyphicon-text-height' => 'text-height',
897 'glyphicon-text-width' => 'text-width',
898 'glyphicon-th' => 'th',
899 'glyphicon-th-large' => 'th-large',
900 'glyphicon-th-list' => 'th-list',
901 'glyphicon-thumbs-down' => 'thumbs-down',
902 'glyphicon-thumbs-up' => 'thumbs-up',
903 'glyphicon-time' => 'time',
904 'glyphicon-tint' => 'tint',
905 'glyphicon-tower' => 'tower',
906 'glyphicon-transfer' => 'transfer',
907 'glyphicon-trash' => 'trash',
908 'glyphicon-tree-conifer' => 'tree-conifer',
909 'glyphicon-tree-deciduous' => 'tree-deciduous',
910 'glyphicon-unchecked' => 'unchecked',
911 'glyphicon-upload' => 'upload',
912 'glyphicon-usd' => 'usd',
913 'glyphicon-user' => 'user',
914 'glyphicon-volume-down' => 'volume-down',
915 'glyphicon-volume-off' => 'volume-off',
916 'glyphicon-volume-up' => 'volume-up',
917 'glyphicon-warning-sign' => 'warning-sign',
918 'glyphicon-wrench' => 'wrench',
919 'glyphicon-zoom-in' => 'zoom-in',
920 'glyphicon-zoom-out' => 'zoom-out',
922 $versions['3.0.1'] = $versions['3.0.0'];
923 $versions['3.0.2'] = $versions['3.0.1'];
924 $versions['3.0.3'] = $versions['3.0.2'];
925 $versions['3.1.0'] = $versions['3.0.3'];
926 $versions['3.1.1'] = $versions['3.1.0'];
927 $versions['3.2.0'] = $versions['3.1.1'];
928 $versions['3.3.0'] = array_merge($versions['3.2.0'], [
929 'glyphicon-eur' => 'eur',
931 $versions['3.3.1'] = $versions['3.3.0'];
932 $versions['3.3.2'] = array_merge($versions['3.3.1'], [
933 'glyphicon-alert' => 'alert',
934 'glyphicon-apple' => 'apple',
935 'glyphicon-baby-formula' => 'baby-formula',
936 'glyphicon-bed' => 'bed',
937 'glyphicon-bishop' => 'bishop',
938 'glyphicon-bitcoin' => 'bitcoin',
939 'glyphicon-blackboard' => 'blackboard',
940 'glyphicon-cd' => 'cd',
941 'glyphicon-console' => 'console',
942 'glyphicon-copy' => 'copy',
943 'glyphicon-duplicate' => 'duplicate',
944 'glyphicon-education' => 'education',
945 'glyphicon-equalizer' => 'equalizer',
946 'glyphicon-erase' => 'erase',
947 'glyphicon-grain' => 'grain',
948 'glyphicon-hourglass' => 'hourglass',
949 'glyphicon-ice-lolly' => 'ice-lolly',
950 'glyphicon-ice-lolly-tasted' => 'ice-lolly-tasted',
951 'glyphicon-king' => 'king',
952 'glyphicon-knight' => 'knight',
953 'glyphicon-lamp' => 'lamp',
954 'glyphicon-level-up' => 'level-up',
955 'glyphicon-menu-down' => 'menu-down',
956 'glyphicon-menu-hamburger' => 'menu-hamburger',
957 'glyphicon-menu-left' => 'menu-left',
958 'glyphicon-menu-right' => 'menu-right',
959 'glyphicon-menu-up' => 'menu-up',
960 'glyphicon-modal-window' => 'modal-window',
961 'glyphicon-object-align-bottom' => 'object-align-bottom',
962 'glyphicon-object-align-horizontal' => 'object-align-horizontal',
963 'glyphicon-object-align-left' => 'object-align-left',
964 'glyphicon-object-align-right' => 'object-align-right',
965 'glyphicon-object-align-top' => 'object-align-top',
966 'glyphicon-object-align-vertical' => 'object-align-vertical',
967 'glyphicon-oil' => 'oil',
968 'glyphicon-open-file' => 'open-file',
969 'glyphicon-option-horizontal' => 'option-horizontal',
970 'glyphicon-option-vertical' => 'option-vertical',
971 'glyphicon-paste' => 'paste',
972 'glyphicon-pawn' => 'pawn',
973 'glyphicon-piggy-bank' => 'piggy-bank',
974 'glyphicon-queen' => 'queen',
975 'glyphicon-ruble' => 'ruble',
976 'glyphicon-save-file' => 'save-file',
977 'glyphicon-scale' => 'scale',
978 'glyphicon-scissors' => 'scissors',
979 'glyphicon-subscript' => 'subscript',
980 'glyphicon-sunglasses' => 'sunglasses',
981 'glyphicon-superscript' => 'superscript',
982 'glyphicon-tent' => 'tent',
983 'glyphicon-text-background' => 'text-background',
984 'glyphicon-text-color' => 'text-color',
985 'glyphicon-text-size' => 'text-size',
986 'glyphicon-triangle-bottom' => 'triangle-bottom',
987 'glyphicon-triangle-left' => 'triangle-left',
988 'glyphicon-triangle-right' => 'triangle-right',
989 'glyphicon-triangle-top' => 'triangle-top',
990 'glyphicon-yen' => 'yen',
992 $versions['3.3.4'] = array_merge($versions['3.3.2'], [
993 'glyphicon-btc' => 'btc',
994 'glyphicon-jpy' => 'jpy',
995 'glyphicon-rub' => 'rub',
996 'glyphicon-xbt' => 'xbt',
998 $versions['3.3.5'] = $versions['3.3.4'];
999 $versions['3.3.6'] = $versions['3.3.5'];
1000 $versions['3.3.7'] = $versions['3.3.6'];
1003 // Return a specific versions icon set.
1004 if (isset($version) && isset($versions[$version])) {
1005 return $versions[$version];
1008 // Return the latest version.
1009 return $versions[self::FRAMEWORK_VERSION];
1013 * Determines if the "cache_context.url.path.is_front" service exists.
1018 * @see \Drupal\bootstrap\Bootstrap::isFront
1019 * @see \Drupal\bootstrap\Bootstrap::preprocess
1020 * @see https://www.drupal.org/node/2829588
1022 public static function hasIsFrontCacheContext() {
1023 static $has_is_front_cache_context;
1024 if (!isset($has_is_front_cache_context)) {
1025 $has_is_front_cache_context = \Drupal::getContainer()->has('cache_context.url.path.is_front');
1027 return $has_is_front_cache_context;
1031 * Initializes the active theme.
1033 final public static function initialize() {
1034 static $initialized = FALSE;
1035 if (!$initialized) {
1036 // Initialize the active theme.
1037 $active_theme = self::getTheme();
1039 // Include deprecated functions.
1040 foreach ($active_theme->getAncestry() as $ancestor) {
1041 if ($ancestor->getSetting('include_deprecated')) {
1042 $files = $ancestor->fileScan('/^deprecated\.php$/');
1043 if ($file = reset($files)) {
1044 $ancestor->includeOnce($file->uri, FALSE);
1049 $initialized = TRUE;
1054 * Determines if the current path is the "front" page.
1056 * *Note:* This method will not return `TRUE` if there is not a proper
1057 * "cache_context.url.path.is_front" service defined.
1059 * *Note:* If using this method in preprocess/render array logic, the proper
1060 * #cache context must also be defined:
1063 * $variables['#cache']['contexts'][] = 'url.path.is_front';
1069 * @see \Drupal\bootstrap\Bootstrap::hasIsFrontCacheContext
1070 * @see \Drupal\bootstrap\Bootstrap::preprocess
1071 * @see https://www.drupal.org/node/2829588
1073 public static function isFront() {
1075 if (!isset($is_front)) {
1077 $is_front = static::hasIsFrontCacheContext() ? \Drupal::service('path.matcher')->isFrontPage() : FALSE;
1079 catch (\Exception $e) {
1087 * Preprocess theme hook variables.
1089 * @param array $variables
1090 * The variables array, passed by reference.
1091 * @param string $hook
1092 * The name of the theme hook.
1093 * @param array $info
1094 * The theme hook info.
1096 public static function preprocess(array &$variables, $hook, array $info) {
1098 if (!isset($theme)) {
1099 $theme = self::getTheme();
1101 static $preprocess_manager;
1102 if (!isset($preprocess_manager)) {
1103 $preprocess_manager = new PreprocessManager($theme);
1106 // Adds a global "is_front" variable back to all templates.
1107 // @see https://www.drupal.org/node/2829585
1108 if (!isset($variables['is_front'])) {
1109 $variables['is_front'] = static::isFront();
1110 if (static::hasIsFrontCacheContext()) {
1111 $variables['#cache']['contexts'][] = 'url.path.is_front';
1115 // Ensure that any default theme hook variables exist. Due to how theme
1116 // hook suggestion alters work, the variables provided are from the
1117 // original theme hook, not the suggestion.
1118 if (isset($info['variables'])) {
1119 $variables = NestedArray::mergeDeepArray([$info['variables'], $variables], TRUE);
1122 // Add active theme context.
1123 // @see https://www.drupal.org/node/2630870
1124 if (!isset($variables['theme'])) {
1125 $variables['theme'] = $theme->getInfo();
1126 $variables['theme']['dev'] = $theme->isDev();
1127 $variables['theme']['livereload'] = $theme->livereloadUrl();
1128 $variables['theme']['name'] = $theme->getName();
1129 $variables['theme']['path'] = $theme->getPath();
1130 $variables['theme']['title'] = $theme->getTitle();
1131 $variables['theme']['settings'] = $theme->settings()->get();
1132 $variables['theme']['has_glyphicons'] = $theme->hasGlyphicons();
1133 $variables['theme']['query_string'] = \Drupal::getContainer()->get('state')->get('system.css_js_query_string') ?: '0';
1136 // Invoke necessary preprocess plugin.
1137 if (isset($info['bootstrap preprocess'])) {
1138 if ($preprocess_manager->hasDefinition($info['bootstrap preprocess'])) {
1139 $class = $preprocess_manager->createInstance($info['bootstrap preprocess'], ['theme' => $theme]);
1140 /** @var \Drupal\bootstrap\Plugin\Preprocess\PreprocessInterface $class */
1141 $class->preprocess($variables, $hook, $info);
1147 * Ensures a value is typecast to a string, rendering an array if necessary.
1149 * @param string|array $value
1150 * The value to typecast, passed by reference.
1153 * The typecast string value.
1155 public static function toString(&$value) {
1156 return (string) (Element::isRenderArray($value) ? Element::create($value)->renderPlain() : $value);