Is there an API to find the title of a page using only its alias ?
I managed to get the internal path with this code (although the multilingual part doesn't feel the easiest option):
/** * Function to resolve an alias and find the internal path, considering language prefixes. */ function get_internal_path_from_alias($alias) { $language_manager = \Drupal::service('language_manager'); // Check if the alias starts with a language code prefix (e.g., /fr, /en, /de). // Get all languages on the site. $languages = $language_manager->getLanguages(); $prefix_found = FALSE; // Loop through the languages to check if the alias contains a language prefix. foreach ($languages as $language) { $langcode = $language->getId(); if (strpos($alias, '/' . $langcode) === 0) { // We found a language prefix, so remove it from the alias. $alias = substr($alias, strlen('/' . $langcode)); $prefix_found = TRUE; break; } } // Get the alias manager service. $alias_manager = \Drupal::service('path_alias.manager'); // If no prefix is found, pass NULL for the language code (default). // If a prefix was found, pass the language code for the alias lookup. if ($prefix_found) { $path = $alias_manager->getPathByAlias($alias, $langcode); } else { $path = $alias_manager->getPathByAlias($alias); } // Return the resolved path (or NULL if not found). return $path; } But after that I'm not sure how to get the title of my internal path ? Also my function doesn't work with views.
What API could I use for this ?