diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 1ed4205a3ce223d4490fb015552f78b5e9aed82a..1bb221529b554abab27b315916e5d197c3bdd5ea 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1520,7 +1520,7 @@ function theme_get_suggestions($args, $base, $delimiter = '__') { $prefix .= $delimiter . $arg; } } - if (drupal_is_front_page()) { + if (\Drupal::service('path.matcher')->isFrontPage()) { // Front templates should be based on root only, not prefixed arguments. $suggestions[] = $base . $delimiter . 'front'; } diff --git a/core/modules/language/src/Plugin/Block/LanguageBlock.php b/core/modules/language/src/Plugin/Block/LanguageBlock.php index 0502d2d610cc19165e5c7c3b03ba89f81679ea95..e86f263da54eb0be34f5a8d1701b9b11ffd58f6a 100644 --- a/core/modules/language/src/Plugin/Block/LanguageBlock.php +++ b/core/modules/language/src/Plugin/Block/LanguageBlock.php @@ -8,6 +8,7 @@ namespace Drupal\language\Plugin\Block; use Drupal\Core\Block\BlockBase; +use Drupal\Core\Path\PathMatcherInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -33,6 +34,13 @@ class LanguageBlock extends BlockBase implements ContainerFactoryPluginInterface */ protected $languageManager; + /** + * The path matcher. + * + * @var \Drupal\Core\Path\PathMatcherInterface + */ + protected $pathMatcher; + /** * Constructs an LanguageBlock object. * @@ -44,10 +52,13 @@ class LanguageBlock extends BlockBase implements ContainerFactoryPluginInterface * The plugin implementation definition. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\Core\Path\PathMatcherInterface $path_matcher + * The path matcher. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, LanguageManagerInterface $language_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, LanguageManagerInterface $language_manager, PathMatcherInterface $path_matcher) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->languageManager = $language_manager; + $this->pathMatcher = $path_matcher; } @@ -59,7 +70,8 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('language_manager') + $container->get('language_manager'), + $container->get('path.matcher') ); } @@ -76,7 +88,7 @@ protected function blockAccess(AccountInterface $account) { */ public function build() { $build = array(); - $route_name = drupal_is_front_page() ? '<front>' : '<current>'; + $route_name = $this->pathMatcher->isFrontPage() ? '<front>' : '<current>'; $type = $this->getDerivativeId(); $links = $this->languageManager->getLanguageSwitchLinks($type, Url::fromRoute($route_name)); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index d395a53748f93f0af572ae88e4f4d095e7e55c4e..8a55125d0d4699e1fed48c86e60e81ae0bcf429f 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -268,7 +268,7 @@ function system_theme_suggestions_maintenance_page(array $variables) { // allow themers to override the page and the content completely. $offline = defined('MAINTENANCE_MODE'); try { - drupal_is_front_page(); + \Drupal::service('path.matcher')->isFrontPage(); } catch (Exception $e) { // The database is not yet available. @@ -609,7 +609,7 @@ function system_page_attachments(array &$page) { // Collect the current state that determines whether a link is active. array( 'path' => \Drupal::routeMatch()->getRouteName() ? Url::fromRouteMatch(\Drupal::routeMatch())->getInternalPath() : '', - 'front' => drupal_is_front_page(), + 'front' => \Drupal::service('path.matcher')->isFrontPage(), 'language' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId(), 'query' => \Drupal::request()->query->all(), ) @@ -641,7 +641,7 @@ function system_js_settings_alter(&$settings, AttachedAssetsInterface $assets) { 'pathPrefix' => $pathPrefix, 'currentPath' => $current_path, 'currentPathIsAdmin' => $current_path_is_admin, - 'isFront' => drupal_is_front_page(), + 'isFront' => \Drupal::service('path.matcher')->isFrontPage(), 'currentLanguage' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId(), ]; if (!empty($current_query)) { diff --git a/core/modules/system/tests/modules/system_test/system_test.module b/core/modules/system/tests/modules/system_test/system_test.module index 5e8a552908d4be308808f7419f1ea400c33cf4d1..fb1538d608e2ccdb142aaa0ec94cee37535d2d79 100644 --- a/core/modules/system/tests/modules/system_test/system_test.module +++ b/core/modules/system/tests/modules/system_test/system_test.module @@ -67,9 +67,10 @@ function system_test_system_info_alter(&$info, Extension $file, $type) { * Implements hook_page_attachments(). */ function system_test_page_attachments(array &$page) { - // Used by FrontPageTestCase to get the results of drupal_is_front_page(). + // Used by FrontPageTestCase to get the results of + // \Drupal::service('path.matcher')->isFrontPage(). $frontpage = \Drupal::state()->get('system_test.front_page_output') ?: 0; - if ($frontpage && drupal_is_front_page()) { + if ($frontpage && \Drupal::service('path.matcher')->isFrontPage()) { drupal_set_message(t('On front page.')); } } diff --git a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php index f28f6e2ff0db4805f26e76013212401f4cf4dc79..f5a82bc9bef93b627e91056cfe716c8b3cb5227b 100644 --- a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php @@ -348,8 +348,7 @@ public function testGenerateWithHtml() { * @see \Drupal\Core\Utility\LinkGenerator::generate() * * @todo Test that the active class is added on the front page when generating - * links to the front page when drupal_is_front_page() is converted to a - * service. + * links to the front page in https://www.drupal.org/node/2420967. */ public function testGenerateActive() { $this->urlGenerator->expects($this->exactly(5)) @@ -489,11 +488,3 @@ protected function assertNoXPathResults($query, $html) { } } -namespace { - // @todo Remove this once there is a service for drupal_is_front_page(). - if (!function_exists('drupal_is_front_page')) { - function drupal_is_front_page() { - return FALSE; - } - } -}