function yandex_metrics_reports_obtain_page_title in Yandex.Metrics 8.2
Same name and namespace in other branches
- 7.2 yandex_metrics_reports/yandex_metrics_reports.module \yandex_metrics_reports_obtain_page_title()
Obtain page title by path and language if possible.
Parameters
string $path:
string $language:
Return value
string
2 calls to yandex_metrics_reports_obtain_page_title()
- YandexMetricsReportsTestCase::testObtainPageTitle in yandex_metrics_reports/
yandex_metrics_reports.test - Test for yandex_metrics_reports_obtain_page_title() function.
- yandex_metrics_reports_save_popular_content in yandex_metrics_reports/
yandex_metrics_reports.module - Fetch Popuplar content from Yandex.metrika and save it to the database.
File
- yandex_metrics_reports/
yandex_metrics_reports.module, line 294 - The main code of Yandex.Metrics Reports module.
Code
function yandex_metrics_reports_obtain_page_title($path, $language = 'en') {
$path = ltrim($path, '/');
$site_frontpage = \Drupal::config('system.site')
->get('page.front');
if (empty($path) || $path == $site_frontpage || $path == $language . '/' . $site_frontpage) {
return \Drupal::config('system.site')
->get('name');
}
// Get normal path, like node/1.
$normal_path = \Drupal::service('path.alias_manager.cached')
->getSystemPath($path);
$item = menu_get_item($normal_path);
if (empty($item) || empty($item['title'])) {
return $path;
}
return $item['title'];
}