Created
June 20, 2017 18:57
-
-
Save mikedotexe/c2a5304f47618dbb7dd9c27b8c727457 to your computer and use it in GitHub Desktop.
Get homepage path of Drupal 8 site from configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\Core\Config\Config; | |
// ... | |
$config = \Drupal::config('system.site'); | |
$front_uri = $config->get('page.front'); | |
$alias = \Drupal::service('path.alias_manager')->getAliasByPath($front_uri); |
tyty. exactly what i was looking for. getPathByAlias doesnt seem to return node id for the frontpage, all the other search results were saying to use that but failed to note it wouldnt work if you were dealing with the front, at least for drupal 8.6.4
If you're doing this in anything but a procedural function, you should make sure to use dependency injection as using the Drupal
global static object is meant only for legacy code and is considered bad practice elsewhere.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That snippet did what I googled for over one hour. Thank you!