comparison core/includes/theme.inc @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
6 * 6 *
7 * The theme system allows for nearly all output of the Drupal system to be 7 * The theme system allows for nearly all output of the Drupal system to be
8 * customized by user themes. 8 * customized by user themes.
9 */ 9 */
10 10
11 use Drupal\Core\Url;
11 use Drupal\Component\Serialization\Json; 12 use Drupal\Component\Serialization\Json;
12 use Drupal\Component\Utility\Crypt; 13 use Drupal\Component\Utility\Crypt;
13 use Drupal\Component\Utility\Html; 14 use Drupal\Component\Utility\Html;
14 use Drupal\Component\Render\MarkupInterface; 15 use Drupal\Component\Render\MarkupInterface;
15 use Drupal\Core\Cache\CacheableDependencyInterface; 16 use Drupal\Core\Cache\CacheableDependencyInterface;
21 use Drupal\Core\Template\Attribute; 22 use Drupal\Core\Template\Attribute;
22 use Drupal\Core\Theme\ThemeSettings; 23 use Drupal\Core\Theme\ThemeSettings;
23 use Drupal\Component\Utility\NestedArray; 24 use Drupal\Component\Utility\NestedArray;
24 use Drupal\Core\Render\Element; 25 use Drupal\Core\Render\Element;
25 use Drupal\Core\Render\Markup; 26 use Drupal\Core\Render\Markup;
27 use Drupal\Core\Utility\TableSort;
26 28
27 /** 29 /**
28 * @defgroup content_flags Content markers 30 * @defgroup content_flags Content markers
29 * @{ 31 * @{
30 * Markers used by mark.html.twig and node_mark() to designate content. 32 * Markers used by mark.html.twig and node_mark() to designate content.
96 } 98 }
97 99
98 /** 100 /**
99 * Returns an array of default theme features. 101 * Returns an array of default theme features.
100 * 102 *
101 * @see \Drupal\Core\Extension\ThemeHandler::$defaultFeatures 103 * @see \Drupal\Core\Extension\ThemeExtensionList::$defaults
102 */ 104 */
103 function _system_default_theme_features() { 105 function _system_default_theme_features() {
104 return [ 106 return [
105 'favicon', 107 'favicon',
106 'logo', 108 'logo',
504 * - attributes['timestamp']: 506 * - attributes['timestamp']:
505 * - timestamp: 507 * - timestamp:
506 * - text: 508 * - text:
507 */ 509 */
508 function template_preprocess_time(&$variables) { 510 function template_preprocess_time(&$variables) {
511 /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
512 $date_formatter = \Drupal::service('date.formatter');
509 // Format the 'datetime' attribute based on the timestamp. 513 // Format the 'datetime' attribute based on the timestamp.
510 // @see http://www.w3.org/TR/html5-author/the-time-element.html#attr-time-datetime 514 // @see http://www.w3.org/TR/html5-author/the-time-element.html#attr-time-datetime
511 if (!isset($variables['attributes']['datetime']) && isset($variables['timestamp'])) { 515 if (!isset($variables['attributes']['datetime']) && isset($variables['timestamp'])) {
512 $variables['attributes']['datetime'] = format_date($variables['timestamp'], 'html_datetime', '', 'UTC'); 516 $variables['attributes']['datetime'] = $date_formatter->format($variables['timestamp'], 'html_datetime', '', 'UTC');
513 } 517 }
514 518
515 // If no text was provided, try to auto-generate it. 519 // If no text was provided, try to auto-generate it.
516 if (!isset($variables['text'])) { 520 if (!isset($variables['text'])) {
517 // Format and use a human-readable version of the timestamp, if any. 521 // Format and use a human-readable version of the timestamp, if any.
518 if (isset($variables['timestamp'])) { 522 if (isset($variables['timestamp'])) {
519 $variables['text'] = format_date($variables['timestamp']); 523 $variables['text'] = $date_formatter->format($variables['timestamp']);
520 } 524 }
521 // Otherwise, use the literal datetime attribute. 525 // Otherwise, use the literal datetime attribute.
522 elseif (isset($variables['attributes']['datetime'])) { 526 elseif (isset($variables['attributes']['datetime'])) {
523 $variables['text'] = $variables['attributes']['datetime']; 527 $variables['text'] = $variables['attributes']['datetime'];
524 } 528 }
942 946
943 // Format the table header: 947 // Format the table header:
944 $ts = []; 948 $ts = [];
945 $header_columns = 0; 949 $header_columns = 0;
946 if (!empty($variables['header'])) { 950 if (!empty($variables['header'])) {
947 $ts = tablesort_init($variables['header']); 951 $ts = TableSort::getContextFromRequest($variables['header'], \Drupal::request());
948 952
949 // Use a separate index with responsive classes as headers 953 // Use a separate index with responsive classes as headers
950 // may be associative. 954 // may be associative.
951 $responsive_index = -1; 955 $responsive_index = -1;
952 foreach ($variables['header'] as $col_key => $cell) { 956 foreach ($variables['header'] as $col_key => $cell) {
986 elseif (in_array(RESPONSIVE_PRIORITY_LOW, $cell['class'])) { 990 elseif (in_array(RESPONSIVE_PRIORITY_LOW, $cell['class'])) {
987 $responsive_classes[$responsive_index] = RESPONSIVE_PRIORITY_LOW; 991 $responsive_classes[$responsive_index] = RESPONSIVE_PRIORITY_LOW;
988 } 992 }
989 } 993 }
990 994
991 tablesort_header($cell_content, $cell, $variables['header'], $ts); 995 TableSort::header($cell_content, $cell, $variables['header'], $ts);
992 996
993 // tablesort_header() removes the 'sort' and 'field' keys. 997 // TableSort::header() removes the 'sort' and 'field' keys.
994 $cell_attributes = new Attribute($cell); 998 $cell_attributes = new Attribute($cell);
995 } 999 }
996 $variables['header'][$col_key] = []; 1000 $variables['header'][$col_key] = [];
997 $variables['header'][$col_key]['tag'] = $is_header ? 'th' : 'td'; 1001 $variables['header'][$col_key]['tag'] = $is_header ? 'th' : 'td';
998 $variables['header'][$col_key]['attributes'] = $cell_attributes; 1002 $variables['header'][$col_key]['attributes'] = $cell_attributes;
1370 $variables['page'][$region] = []; 1374 $variables['page'][$region] = [];
1371 } 1375 }
1372 } 1376 }
1373 1377
1374 $variables['base_path'] = base_path(); 1378 $variables['base_path'] = base_path();
1375 $variables['front_page'] = \Drupal::url('<front>'); 1379 $variables['front_page'] = Url::fromRoute('<front>')->toString();
1376 $variables['language'] = $language_interface; 1380 $variables['language'] = $language_interface;
1377 1381
1378 // An exception might be thrown. 1382 // An exception might be thrown.
1379 try { 1383 try {
1380 $variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage(); 1384 $variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
1604 * - element: A render element representing the form element. 1608 * - element: A render element representing the form element.
1605 */ 1609 */
1606 function template_preprocess_field_multiple_value_form(&$variables) { 1610 function template_preprocess_field_multiple_value_form(&$variables) {
1607 $element = $variables['element']; 1611 $element = $variables['element'];
1608 $variables['multiple'] = $element['#cardinality_multiple']; 1612 $variables['multiple'] = $element['#cardinality_multiple'];
1613 $variables['attributes'] = $element['#attributes'];
1609 1614
1610 if ($variables['multiple']) { 1615 if ($variables['multiple']) {
1611 $table_id = Html::getUniqueId($element['#field_name'] . '_values'); 1616 $table_id = Html::getUniqueId($element['#field_name'] . '_values');
1612 $order_class = $element['#field_name'] . '-delta-order'; 1617 $order_class = $element['#field_name'] . '-delta-order';
1613 $header_attributes = new Attribute(['class' => ['label']]); 1618 $header_attributes = new Attribute(['class' => ['label']]);