Projet

Général

Profil

Révision eefc2ac0

Ajouté par Assos Assos il y a plus de 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/themes/bootstrap/includes/common.inc
1 1
<?php
2

  
2 3
/**
3 4
 * @file
4 5
 * List of common helper functions for use in Bootstrap based themes.
......
31 32
 * @param int $length
32 33
 *   The length of characters to determine if description is "simple".
33 34
 */
34
function bootstrap_element_smart_description(&$element, &$target = NULL, $input_only = TRUE, $length = NULL) {
35
function bootstrap_element_smart_description(array &$element, array &$target = NULL, $input_only = TRUE, $length = NULL) {
35 36
  // Determine if tooltips are enabled.
36 37
  static $enabled;
37 38
  if (!isset($enabled)) {
......
185 186
    if (function_exists($function)) {
186 187
      $function($data, $theme);
187 188
    }
188
    // @todo Use drupal_alter() once CDN is in bootstrap_core companion module.
189
    // drupal_alter('bootstrap_cdn_provider_' . $provider . '_assets', $data, $theme);
190

  
191 189
    // Iterate over each type.
192 190
    foreach ($types as $type) {
193 191
      if (variable_get("preprocess_$type", FALSE) && !empty($data['min'][$type])) {
......
312 310
 * @param string $prefix
313 311
 *   The prefix used on the $name of the setting, this will be appended with
314 312
 *   "_" automatically if set.
313
 * @param mixed $default
314
 *   The default value to return if setting doesn't exist or is not set.
315 315
 *
316 316
 * @return mixed
317 317
 *   The value of the requested setting, NULL if the setting does not exist.
......
320 320
 *
321 321
 * @todo Refactor in 7.x-4.x and get rid of the deprecated settings.
322 322
 */
323
function bootstrap_setting($name, $theme = NULL, $prefix = 'bootstrap') {
323
function bootstrap_setting($name, $theme = NULL, $prefix = 'bootstrap', $default = NULL) {
324 324
  $prefix = !empty($prefix) ? $prefix . '_' : '';
325 325
  $setting = theme_get_setting($prefix . $name, $theme);
326 326
  switch ($prefix . $name) {
......
360 360
      break;
361 361

  
362 362
  }
363
  return $setting;
363
  return isset($setting) ? $setting : $default;
364 364
}
365 365

  
366 366
/**
......
379 379
 * @return array
380 380
 *   The attributes array. Passed by reference.
381 381
 */
382
function &_bootstrap_get_attributes(&$element, $property = 'attributes') {
382
function &_bootstrap_get_attributes(array &$element, $property = 'attributes') {
383 383
  // Attempt to retrieve a renderable element attributes first.
384 384
  if (
385 385
    isset($element['#type']) ||
......
428 428
 * @return array
429 429
 *   The classes array. Passed by reference.
430 430
 */
431
function &_bootstrap_get_classes(&$element, $property = 'attributes') {
431
function &_bootstrap_get_classes(array &$element, $property = 'attributes') {
432 432
  $attributes = &_bootstrap_get_attributes($element, $property);
433 433

  
434 434
  if (!isset($attributes['class'])) {
......
461 461
 *   normal attributes, but can be "wrapper_attributes" or
462 462
 *   "input_group_attributes".
463 463
 */
464
function _bootstrap_add_class($class, &$element, $property = 'attributes') {
464
function _bootstrap_add_class($class, array &$element, $property = 'attributes') {
465 465
  // Retrieve the element's classes.
466 466
  $classes = &_bootstrap_get_classes($element, $property);
467 467

  
......
494 494
 *   normal attributes, but can be "wrapper_attributes" or
495 495
 *   "input_group_attributes".
496 496
 */
497
function _bootstrap_remove_class($class, &$element, $property = 'attributes') {
497
function _bootstrap_remove_class($class, array &$element, $property = 'attributes') {
498 498
  // Retrieve the element's classes.
499 499
  $classes = &_bootstrap_get_classes($element, $property);
500 500

  
......
961 961
 * backport of 8.x-3.x code so the added $attributes parameter can be more
962 962
 * easily dealt with.
963 963
 *
964
 * @see https://www.drupal.org/project/bootstrap/issues/2844885
965
 *
966 964
 * @param string $name
967 965
 *   The icon name, minus the "glyphicon-" prefix.
968 966
 * @param array|string $default
......
970 968
 * @param array $attributes
971 969
 *   (Optional) Additional attributes to merge onto the icon.
972 970
 *
971
 * @see https://www.drupal.org/project/bootstrap/issues/2844885
972
 *
973 973
 * @return array
974 974
 *   The render containing the icon defined by $name, $default value if
975 975
 *   icon does not exist or returns NULL if no icon could be rendered.
......
1018 1018
 * Determine whether or not Bootstrap Glyphicons can be used.
1019 1019
 */
1020 1020
function _bootstrap_glyphicons_supported() {
1021
  global $theme;
1022

  
1021 1023
  // Use the advanced drupal_static() pattern, since this has the potential to
1022 1024
  // be called very often by _bootstrap_icon().
1023 1025
  static $drupal_static_fast;
1024 1026
  if (!isset($drupal_static_fast)) {
1025 1027
    $drupal_static_fast['supported'] = &drupal_static(__FUNCTION__);
1026
    // Get the active theme.
1027
    $drupal_static_fast['theme'] = variable_get('theme_default', $GLOBALS['theme']);
1028 1028
  }
1029 1029

  
1030 1030
  // Get static data.
1031 1031
  $supported = &$drupal_static_fast['supported'];
1032
  $theme = &$drupal_static_fast['theme'];
1033 1032

  
1034 1033
  // Retrieve supported themes.
1035 1034
  if (!isset($supported)) {
......
1040 1039
    if (($cache = cache_get($cid)) && !empty($cache->data)) {
1041 1040
      $supported = $cache->data;
1042 1041
    }
1042
  }
1043 1043

  
1044
    if (!isset($supported[$theme])) {
1045
      // Bootstrap based themes are enabled by default to use CDN. Check if
1046
      // that is the case here so no file discovery is necessary. If the active
1047
      // theme does not have this setting, it falls back to the base theme that
1048
      // does.
1049
      $supported[$theme] = !!bootstrap_get_cdn_assets('css', NULL, $theme);
1050

  
1051
      // CDN not used, iterate over all of the active (base) themes to determine
1052
      // if they contain glyphicon font files.
1053
      if (!$supported[$theme]) {
1054
        foreach (_bootstrap_get_base_themes($theme, TRUE) as $_theme) {
1055
          // Scan the theme for files.
1056
          $fonts = _bootstrap_file_scan_directory(drupal_get_path('theme', $_theme), '/glyphicons-halflings-regular\.(eot|svg|ttf|woff)$/');
1057

  
1058
          // Fonts found, stop the search.
1059
          if (!empty($fonts)) {
1060
            $supported[$theme] = TRUE;
1061
            break;
1062
          }
1044
  // Determine active theme support if not yet set.
1045
  if (!isset($supported[$theme])) {
1046
    // Bootstrap based themes are enabled by default to use CDN. Check if
1047
    // that is the case here so no file discovery is necessary. If the active
1048
    // theme does not have this setting, it falls back to the base theme that
1049
    // does.
1050
    $supported[$theme] = !!bootstrap_get_cdn_assets('css', NULL, $theme);
1051

  
1052
    // CDN not used, iterate over all of the active (base) themes to determine
1053
    // if they contain glyphicon font files.
1054
    if (!$supported[$theme]) {
1055
      foreach (_bootstrap_get_base_themes($theme, TRUE) as $_theme) {
1056
        // Scan the theme for files.
1057
        $fonts = _bootstrap_file_scan_directory(drupal_get_path('theme', $_theme), '/glyphicons-halflings-regular\.(eot|svg|ttf|woff)$/');
1058

  
1059
        // Fonts found, stop the search.
1060
        if (!empty($fonts)) {
1061
          $supported[$theme] = TRUE;
1062
          break;
1063 1063
        }
1064 1064
      }
1065

  
1066
      // Cache all supported themes now that this theme is added to the array.
1067
      cache_set($cid, $supported);
1068 1065
    }
1066

  
1067
    // Cache all supported themes now that this theme is added to the array.
1068
    cache_set($cid, $supported);
1069 1069
  }
1070

  
1070 1071
  return $supported[$theme];
1071 1072
}
1072 1073

  
......
1079 1080
 * @return bool
1080 1081
 *   TRUE or FALSE.
1081 1082
 */
1082
function _bootstrap_is_button($element) {
1083
function _bootstrap_is_button(array $element) {
1083 1084
  return
1084 1085
    !empty($element['#type']) &&
1085 1086
    !empty($element['#value']) && (
......
1095 1096
 * @param array $element
1096 1097
 *   The form element, passed by reference.
1097 1098
 */
1098
function _bootstrap_colorize_button(&$element) {
1099
function _bootstrap_colorize_button(array &$element) {
1099 1100
  if (_bootstrap_is_button($element)) {
1100 1101
    // Do not add the class if one is already present in the array.
1101 1102
    $button_classes = array(
......
1216 1217
 * @param array $element
1217 1218
 *   The form element, passed by reference.
1218 1219
 */
1219
function _bootstrap_iconize_button(&$element) {
1220
function _bootstrap_iconize_button(array &$element) {
1220 1221
  if (bootstrap_setting('button_iconize') && _bootstrap_is_button($element) && ($icon = _bootstrap_iconize_text($element['#value']))) {
1221 1222
    $element['#icon'] = $icon;
1222 1223
  }
......
1295 1296
 * @param array $variables
1296 1297
 *   The theme implementation variables array.
1297 1298
 */
1298
function _bootstrap_preprocess_theme_suggestion(&$variables) {
1299
function _bootstrap_preprocess_theme_suggestion(array &$variables) {
1299 1300
  $registry = theme_get_registry();
1300 1301
  if (!empty($variables['theme_hook_suggestion']) && !empty($registry[$variables['theme_hook_suggestion']]['preprocess functions'])) {
1301 1302
    // Save the suggestion as the hook to pass to the function.
......
1324 1325
 * @param array $variables
1325 1326
 *   The theme implementation variables array.
1326 1327
 */
1327
function _bootstrap_process_theme_suggestion(&$variables) {
1328
function _bootstrap_process_theme_suggestion(array &$variables) {
1328 1329
  $registry = theme_get_registry();
1329 1330
  if (!empty($variables['theme_hook_suggestion']) && !empty($registry[$variables['theme_hook_suggestion']]['process functions'])) {
1330 1331
    // Save the suggestion as the hook to pass to the function.
......
1351 1352
 *
1352 1353
 * @param string $string
1353 1354
 *   The string of text to check "simple" criteria on.
1354
 * @param int|FALSE $length
1355
 * @param int|false $length
1355 1356
 *   The length of characters used to determine whether or not $string is
1356 1357
 *   considered "simple". Set explicitly to FALSE to disable this criteria.
1357
 * @param array|FALSE $allowed_tags
1358
 * @param array|false $allowed_tags
1358 1359
 *   An array of allowed tag elements. Set explicitly to FALSE to disable this
1359 1360
 *   criteria.
1360 1361
 * @param bool $html

Formats disponibles : Unified diff