Mercurial > hg > isophonics-drupal-site
comparison core/includes/theme.inc @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
10 | 10 |
11 use Drupal\Component\Serialization\Json; | 11 use Drupal\Component\Serialization\Json; |
12 use Drupal\Component\Utility\Crypt; | 12 use Drupal\Component\Utility\Crypt; |
13 use Drupal\Component\Utility\Html; | 13 use Drupal\Component\Utility\Html; |
14 use Drupal\Component\Render\MarkupInterface; | 14 use Drupal\Component\Render\MarkupInterface; |
15 use Drupal\Component\Utility\Unicode; | |
16 use Drupal\Core\Cache\CacheableDependencyInterface; | 15 use Drupal\Core\Cache\CacheableDependencyInterface; |
17 use Drupal\Core\Config\Config; | 16 use Drupal\Core\Config\Config; |
18 use Drupal\Core\Config\StorageException; | 17 use Drupal\Core\Config\StorageException; |
19 use Drupal\Core\Render\AttachmentsInterface; | 18 use Drupal\Core\Render\AttachmentsInterface; |
20 use Drupal\Core\Render\BubbleableMetadata; | 19 use Drupal\Core\Render\BubbleableMetadata; |
342 } | 341 } |
343 } | 342 } |
344 | 343 |
345 // Generate the path to the logo image. | 344 // Generate the path to the logo image. |
346 if ($cache[$theme]->get('logo.use_default')) { | 345 if ($cache[$theme]->get('logo.use_default')) { |
347 $cache[$theme]->set('logo.url', file_url_transform_relative(file_create_url($theme_object->getPath() . '/logo.svg'))); | 346 $logo = \Drupal::service('theme.initialization')->getActiveThemeByName($theme)->getLogo(); |
347 $cache[$theme]->set('logo.url', file_url_transform_relative(file_create_url($logo))); | |
348 } | 348 } |
349 elseif ($logo_path = $cache[$theme]->get('logo.path')) { | 349 elseif ($logo_path = $cache[$theme]->get('logo.path')) { |
350 $cache[$theme]->set('logo.url', file_url_transform_relative(file_create_url($logo_path))); | 350 $cache[$theme]->set('logo.url', file_url_transform_relative(file_create_url($logo_path))); |
351 } | 351 } |
352 | 352 |
483 } | 483 } |
484 elseif ($key == 'favicon_mimetype') { | 484 elseif ($key == 'favicon_mimetype') { |
485 $config->set('favicon.mimetype', $value); | 485 $config->set('favicon.mimetype', $value); |
486 } | 486 } |
487 elseif (substr($key, 0, 7) == 'toggle_') { | 487 elseif (substr($key, 0, 7) == 'toggle_') { |
488 $config->set('features.' . Unicode::substr($key, 7), $value); | 488 $config->set('features.' . mb_substr($key, 7), $value); |
489 } | 489 } |
490 elseif (!in_array($key, ['theme', 'logo_upload'])) { | 490 elseif (!in_array($key, ['theme', 'logo_upload'])) { |
491 $config->set($key, $value); | 491 $config->set($key, $value); |
492 } | 492 } |
493 } | 493 } |
568 function template_preprocess_datetime_wrapper(&$variables) { | 568 function template_preprocess_datetime_wrapper(&$variables) { |
569 $element = $variables['element']; | 569 $element = $variables['element']; |
570 | 570 |
571 if (!empty($element['#title'])) { | 571 if (!empty($element['#title'])) { |
572 $variables['title'] = $element['#title']; | 572 $variables['title'] = $element['#title']; |
573 // If the element title is a string, wrap it a render array so that markup | |
574 // will not be escaped (but XSS-filtered). | |
575 if (is_string($variables['title']) && $variables['title'] !== '') { | |
576 $variables['title'] = ['#markup' => $variables['title']]; | |
577 } | |
573 } | 578 } |
574 | 579 |
575 // Suppress error messages. | 580 // Suppress error messages. |
576 $variables['errors'] = NULL; | 581 $variables['errors'] = NULL; |
577 | 582 |
622 * l() as its $options parameter. | 627 * l() as its $options parameter. |
623 * - attributes: A keyed array of attributes for the <ul> containing the list | 628 * - attributes: A keyed array of attributes for the <ul> containing the list |
624 * of links. | 629 * of links. |
625 * - set_active_class: (optional) Whether each link should compare the | 630 * - set_active_class: (optional) Whether each link should compare the |
626 * route_name + route_parameters or href (path), language and query options | 631 * route_name + route_parameters or href (path), language and query options |
627 * to the current URL, to determine whether the link is "active". If so, an | 632 * to the current URL, to determine whether the link is "active". If so, |
628 * "active" class will be applied to the list item containing the link, as | 633 * attributes will be added to the HTML elements for both the link and the |
629 * well as the link itself. It is important to use this sparingly since it | 634 * list item that contains it, which will result in an "is-active" class |
630 * is usually unnecessary and requires extra processing. | 635 * being added to both. The class is added via JavaScript for authenticated |
631 * For anonymous users, the "active" class will be calculated on the server, | 636 * users (in the active-link library), and via PHP for anonymous users (in |
632 * because most sites serve each anonymous user the same cached page anyway. | 637 * the \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter class). |
633 * For authenticated users, the "active" class will be calculated on the | |
634 * client (through JavaScript), only data- attributes are added to list | |
635 * items and contained links, to prevent breaking the render cache. The | |
636 * JavaScript is added in system_page_attachments(). | |
637 * - heading: (optional) A heading to precede the links. May be an | 638 * - heading: (optional) A heading to precede the links. May be an |
638 * associative array or a string. If it's an array, it can have the | 639 * associative array or a string. If it's an array, it can have the |
639 * following elements: | 640 * following elements: |
640 * - text: The heading text. | 641 * - text: The heading text. |
641 * - level: The heading level (e.g. 'h2', 'h3'). | 642 * - level: The heading level (e.g. 'h2', 'h3'). |
691 '#url' => $link['url'], | 692 '#url' => $link['url'], |
692 '#ajax' => $link['ajax'], | 693 '#ajax' => $link['ajax'], |
693 ]; | 694 ]; |
694 | 695 |
695 // Handle links and ensure that the active class is added on the LIs, but | 696 // Handle links and ensure that the active class is added on the LIs, but |
696 // only if the 'set_active_class' option is not empty. | 697 // only if the 'set_active_class' option is not empty. Links templates |
698 // duplicate the "is-active" class handling of l() and | |
699 // LinkGenerator::generate() because they need to be able to set the | |
700 // "is-active" class not on the links themselves (<a> tags), but on the | |
701 // list items (<li> tags) that contain the links. This is necessary for | |
702 // CSS to be able to style list items differently when the link is active, | |
703 // since CSS does not yet allow one to style list items only if they | |
704 // contain a certain element with a certain class. That is, we cannot yet | |
705 // convert this jQuery selector to a CSS selector: | |
706 // jQuery('li:has("a.is-active")') | |
697 if (isset($link['url'])) { | 707 if (isset($link['url'])) { |
698 if (!empty($variables['set_active_class'])) { | 708 if (!empty($variables['set_active_class'])) { |
699 | 709 |
700 // Also enable set_active_class for the contained link. | 710 // Also enable set_active_class for the contained link. |
701 $link_element['#options']['set_active_class'] = TRUE; | 711 $link_element['#options']['set_active_class'] = TRUE; |
704 $li_attributes['hreflang'] = $link['language']->getId(); | 714 $li_attributes['hreflang'] = $link['language']->getId(); |
705 } | 715 } |
706 | 716 |
707 // Add a "data-drupal-link-query" attribute to let the | 717 // Add a "data-drupal-link-query" attribute to let the |
708 // drupal.active-link library know the query in a standardized manner. | 718 // drupal.active-link library know the query in a standardized manner. |
719 // Only add the data- attribute. The "is-active" class will be | |
720 // calculated using JavaScript, to prevent breaking the render cache. | |
709 if (!empty($link['query'])) { | 721 if (!empty($link['query'])) { |
710 $query = $link['query']; | 722 $query = $link['query']; |
711 ksort($query); | 723 ksort($query); |
712 $li_attributes['data-drupal-link-query'] = Json::encode($query); | 724 $li_attributes['data-drupal-link-query'] = Json::encode($query); |
713 } | 725 } |
714 | 726 |
715 /** @var \Drupal\Core\Url $url */ | 727 /** @var \Drupal\Core\Url $url */ |
716 $url = $link['url']; | 728 $url = $link['url']; |
717 if ($url->isRouted()) { | 729 if ($url->isRouted()) { |
718 // Add a "data-drupal-link-system-path" attribute to let the | 730 // Add a "data-drupal-link-system-path" attribute to let the |
719 // drupal.active-link library know the path in a standardized manner. | 731 // drupal.active-link library know the path in a standardized |
732 // manner. Only add the data- attribute. The "is-active" class will | |
733 // be calculated using JavaScript, to prevent breaking the render | |
734 // cache. | |
720 $system_path = $url->getInternalPath(); | 735 $system_path = $url->getInternalPath(); |
721 // @todo System path is deprecated - use the route name and parameters. | 736 // @todo System path is deprecated - use the route name and parameters. |
722 // Special case for the front page. | 737 // Special case for the front page. |
723 $li_attributes['data-drupal-link-system-path'] = $system_path == '' ? '<front>' : $system_path; | 738 $li_attributes['data-drupal-link-system-path'] = $system_path == '' ? '<front>' : $system_path; |
724 } | 739 } |
1354 if (!isset($variables['page'][$region])) { | 1369 if (!isset($variables['page'][$region])) { |
1355 $variables['page'][$region] = []; | 1370 $variables['page'][$region] = []; |
1356 } | 1371 } |
1357 } | 1372 } |
1358 | 1373 |
1359 $variables['base_path'] = base_path(); | 1374 $variables['base_path'] = base_path(); |
1360 $variables['front_page'] = \Drupal::url('<front>'); | 1375 $variables['front_page'] = \Drupal::url('<front>'); |
1361 $variables['language'] = $language_interface; | 1376 $variables['language'] = $language_interface; |
1362 | 1377 |
1363 // An exception might be thrown. | 1378 // An exception might be thrown. |
1364 try { | 1379 try { |
1365 $variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage(); | 1380 $variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage(); |
1366 } | 1381 } |