Skip to content

Instantly share code, notes, and snippets.

@heyrocker
Created October 31, 2016 22:30
Show Gist options
  • Save heyrocker/2e4c294b69ece1895d7c40a47ed98e24 to your computer and use it in GitHub Desktop.
Save heyrocker/2e4c294b69ece1895d7c40a47ed98e24 to your computer and use it in GitHub Desktop.
<?php
public function getSOMPath($url, $path, $langcode) {
// Load the site's parent link configuration.
/** @var \Drupal\Core\Config\ImmutableConfig $site_config */
$site_config = \Drupal::config('som_breadcrumb.settings');
$data = $site_config->get('site.active_trail');
// Load the site homepage alias
$site_config = \Drupal::config('system.site');
$site_homepage_path = $site_config->get('page.front');
// Get the current alias from the path
$som_path = !($url->getOption('alias')) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $langcode) : $path;
// Get the site homepage alias from the path
$site_homepage_alias = !($url->getOption('alias')) ? \Drupal::service('path.alias_manager')->getAliasByPath($site_homepage_path, $langcode) : $site_homepage_path;
// Explode the current alias into component parts
$som_path_array = explode('/', $som_path);
// If the first part of the current alias equals the site homepage alias, remove it
if ($som_path_array[0] == $site_homepage_alias) {
array_shift($som_path_array);
$som_path = implode("/", $som_path_array);
}
return $som_path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment