Back to RouteHelper class

Method getCategoryRoute

public static string
getCategoryRoute
(mixed $catid, mixed $language = 0, mixed $extension = '')
Fetches the category route
Parameters
  • mixed $catid Category ID or CategoryNode instance
  • mixed $language Language code
  • string $extension Extension to lookup
Returns
  • string
Since
  • 3.2
-
  • \InvalidArgumentException
Class: RouteHelper
Project: Joomla

Method getCategoryRoute - Source code

/**
 * Fetches the category route
 *
 * @param   mixed   $catid      Category ID or CategoryNode instance
 * @param   mixed   $language   Language code
 * @param   string  $extension  Extension to lookup
 *
 * @return  string
 *
 * @since   3.2
 *
 * @throws  \InvalidArgumentException
 */
public static function getCategoryRoute($catid, $language = 0, $extension = '')
{
    // Note: $extension is required but has to be an optional argument in the function call due to argument order
    if (empty($extension)) {
        throw new \InvalidArgumentException(sprintf('$extension is a required argument in %s()', __METHOD__));
    }
    if ($catid instanceof CategoryNode) {
        $id = $catid->id;
        $category = $catid;
    } else {
        $extensionName = ucfirst(substr($extension, 4));
        $id = (int) $catid;
        $category = Categories::getInstance($extensionName)->get($id);
    }
    if ($id < 1) {
        $link = '';
    } else {
        $link = 'index.php?option=' . $extension . '&view=category&id=' . $id;
        $needles = array('category' => array($id));
        if ($language && $language !== '*' && Multilanguage::isEnabled()) {
            $link .= '&lang=' . $language;
            $needles['language'] = $language;
        }
        // Create the link
        if ($category) {
            $catids = array_reverse($category->getPath());
            $needles['category'] = $catids;
            $needles['categories'] = $catids;
        }
        if ($item = static::lookupItem($needles)) {
            $link .= '&Itemid=' . $item;
        }
    }
    return $link;
}