Back to SiteRouter class

Method buildSefRoute

public void
buildSefRoute
(mixed &$router, mixed &$uri)
Build the SEF route
Parameters
  • \Joomla\CMS\Router\SiteRouter & $router Router object
  • \Joomla\CMS\Uri\Uri & $uri URI object to process
Returns
  • void
Since
  • 4.0.0
Class: SiteRouter
Project: Joomla

Method buildSefRoute - Source code

/**
 * Build the SEF route
 *
 * @param   SiteRouter  &$router  Router object
 * @param   Uri         &$uri     URI object to process
 *
 * @return  void
 *
 * @since   4.0.0
 */
public function buildSefRoute(&$router, &$uri)
{
    // Get the query data
    $query = $uri->getQuery(true);
    if (!isset($query['option'])) {
        return;
    }
    // Get Menu Item
    $item = empty($query['Itemid']) ? null : $this->menu->getItem($query['Itemid']);
    // Build the component route
    $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $query['option']);
    $crouter = $this->getComponentRouter($component);
    $parts = $crouter->build($query);
    $tmp = trim(implode('/', $parts));
    // Build the application route
    if ($item !== null && $query['option'] === $item->component) {
        if (!$item->home) {
            $tmp = $tmp ? $item->route . '/' . $tmp : $item->route;
        }
        unset($query['Itemid']);
    } else {
        $tmp = 'component/' . substr($query['option'], 4) . '/' . $tmp;
    }
    // Get the route
    if ($tmp) {
        $uri->setPath($uri->getPath() . '/' . $tmp);
    }
    // Unset unneeded query information
    unset($query['option']);
    // Set query again in the URI
    $uri->setQuery($query);
}